
<!DOCTYPE HTML>
<html lang="zh-hans" >
    <head>
        <meta charset="UTF-8">
        <meta content="text/html; charset=utf-8" http-equiv="Content-Type">
        <title>控件绘制流程 · Aivin开发笔记</title>
        <meta http-equiv="X-UA-Compatible" content="IE=edge" />
        <meta name="description" content="">
        <meta name="generator" content="GitBook 3.2.3">
        <meta name="author" content="Aivin">
        
        
    
    <link rel="stylesheet" href="../../gitbook/style.css">

    
            
                
                <link rel="stylesheet" href="../../gitbook/gitbook-plugin-search-plus/search.css">
                
            
                
                <link rel="stylesheet" href="../../gitbook/gitbook-plugin-anchor-navigation-ex/style/plugin.css">
                
            
                
                <link rel="stylesheet" href="../../gitbook/gitbook-plugin-fontsettings/website.css">
                
            
                
                <link rel="stylesheet" href="../../gitbook/gitbook-plugin-tbfed-pagefooter/footer.css">
                
            
                
                <link rel="stylesheet" href="../../gitbook/gitbook-plugin-local-video/video-js.min.css">
                
            
                
                <link rel="stylesheet" href="../../gitbook/gitbook-plugin-splitter/splitter.css">
                
            
                
                <link rel="stylesheet" href="../../gitbook/gitbook-plugin-expandable-chapters/expandable-chapters.css">
                
            
                
                <link rel="stylesheet" href="../../gitbook/gitbook-plugin-highlight/website.css">
                
            
                
                <link rel="stylesheet" href="../../gitbook/gitbook-plugin-theme-comscore/test.css">
                
            
        

    

    
        
        <link rel="stylesheet" href="../../styles/website.css">
        
    

        
    
    
    
    <meta name="HandheldFriendly" content="true"/>
    <meta name="viewport" content="width=device-width, initial-scale=1, user-scalable=no">
    <meta name="apple-mobile-web-app-capable" content="yes">
    <meta name="apple-mobile-web-app-status-bar-style" content="black">
    <link rel="apple-touch-icon-precomposed" sizes="152x152" href="../../gitbook/images/apple-touch-icon-precomposed-152.png">
    <link rel="shortcut icon" href="../../gitbook/images/favicon.ico" type="image/x-icon">

    
    <link rel="next" href="常用shape.html" />
    
    
    <link rel="prev" href="事件分发机制.html" />
    

    
        <link rel="shortcut icon" href='../../assets/images/favicon.ico' type="image/x-icon">
    
    
        <link rel="bookmark" href='../../assets/images/favicon.ico' type="image/x-icon">
    
    
    

    </head>
    <body>
        
<div class="book">
    <div class="book-summary">
        
            
<div id="book-search-input" role="search">
    <input type="text" placeholder="输入并搜索" />
</div>

            
                <nav role="navigation">
                


<ul class="summary">
    
    

    

    
        
        
    
        <li class="chapter " data-level="1.1" data-path="../../">
            
                <a href="../../">
            
                    
                    首页
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.2" data-path="../doc/常用网站.html">
            
                <a href="../doc/常用网站.html">
            
                    
                    常用网站
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.3" data-path="../常用软件/常用软件和框架.html">
            
                <a href="../常用软件/常用软件和框架.html">
            
                    
                    常用软件和框架
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.4" data-path="../doc/开发规范.html">
            
                <a href="../doc/开发规范.html">
            
                    
                    开发规范
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.5" data-path="../doc/开源软件.html">
            
                <a href="../doc/开源软件.html">
            
                    
                    开源软件和框架
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.6" data-path="../doc/Android常用代码.html">
            
                <a href="../doc/Android常用代码.html">
            
                    
                    Android常用代码
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.7" data-path="../源码阅读/源码阅读配置.html">
            
                <a href="../源码阅读/源码阅读配置.html">
            
                    
                    源码阅读
            
                </a>
            

            
            <ul class="articles">
                
    
        <li class="chapter " data-level="1.7.1" data-path="../源码阅读/其他框架源码.html">
            
                <a href="../源码阅读/其他框架源码.html">
            
                    
                    其他框架源码
            
                </a>
            

            
        </li>
    

            </ul>
            
        </li>
    
        <li class="chapter " data-level="1.8" data-path="../产品经理/产品经理.html">
            
                <a href="../产品经理/产品经理.html">
            
                    
                    产品经理
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.9" data-path="../设计模式/设计模式.html">
            
                <a href="../设计模式/设计模式.html">
            
                    
                    设计模式
            
                </a>
            

            
            <ul class="articles">
                
    
        <li class="chapter " data-level="1.9.1" data-path="../设计模式/设计模式.html">
            
                <a href="../设计模式/设计模式.html">
            
                    
                    设计模式
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.9.2" data-path="../设计模式/模式详解.html">
            
                <a href="../设计模式/模式详解.html">
            
                    
                    模式详解
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.9.3" data-path="../设计模式/mvc等.html">
            
                <a href="../设计模式/mvc等.html">
            
                    
                    mvc等
            
                </a>
            

            
        </li>
    

            </ul>
            
        </li>
    
        <li class="chapter " data-level="1.10" data-path="../数据结构/常用数据结构.html">
            
                <a href="../数据结构/常用数据结构.html">
            
                    
                    基本算法
            
                </a>
            

            
            <ul class="articles">
                
    
        <li class="chapter " data-level="1.10.1" data-path="../数据结构/常用数据结构.html">
            
                <a href="../数据结构/常用数据结构.html">
            
                    
                    常用数据结构
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.10.2" data-path="../常用算法/算法术语.html">
            
                <a href="../常用算法/算法术语.html">
            
                    
                    算法术语
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.10.3" data-path="../常用算法/排序算法.html">
            
                <a href="../常用算法/排序算法.html">
            
                    
                    排序算法
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.10.4" data-path="../常用算法/查找算法.html">
            
                <a href="../常用算法/查找算法.html">
            
                    
                    查找算法
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.10.5" data-path="../常用算法/大数相加.html">
            
                <a href="../常用算法/大数相加.html">
            
                    
                    大数相加
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.10.6" data-path="../常用算法/集合的所有子集.html">
            
                <a href="../常用算法/集合的所有子集.html">
            
                    
                    获得集合的所有子集
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.10.7" data-path="../常用算法/扫描线种子填充算法.html">
            
                <a href="../常用算法/扫描线种子填充算法.html">
            
                    
                    扫描线种子填充算法
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.10.8" data-path="../常用算法/其他算法.html">
            
                <a href="../常用算法/其他算法.html">
            
                    
                    其他算法
            
                </a>
            

            
        </li>
    

            </ul>
            
        </li>
    
        <li class="chapter " data-level="1.11" data-path="../java基础/原码补码反码.html">
            
                <a href="../java基础/原码补码反码.html">
            
                    
                    Java部分
            
                </a>
            

            
            <ul class="articles">
                
    
        <li class="chapter " data-level="1.11.1" data-path="../java基础/原码补码反码.html">
            
                <a href="../java基础/原码补码反码.html">
            
                    
                    原码补码反码
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.11.2" data-path="../java基础/java常用代码.html">
            
                <a href="../java基础/java常用代码.html">
            
                    
                    java常用代码
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.11.3" data-path="../java基础/JVM详解.html">
            
                <a href="../java基础/JVM详解.html">
            
                    
                    JVM详解
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.11.4" data-path="../java基础/类加载机制.html">
            
                <a href="../java基础/类加载机制.html">
            
                    
                    类加载机制
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.11.5" data-path="../java基础/内存模型.html">
            
                <a href="../java基础/内存模型.html">
            
                    
                    内存模型
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.11.6" data-path="../java基础/GC机制.html">
            
                <a href="../java基础/GC机制.html">
            
                    
                    GC机制
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.11.7" data-path="../java基础/对象内存布局.html">
            
                <a href="../java基础/对象内存布局.html">
            
                    
                    对象内存布局
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.11.8" data-path="../java基础/继承多态.html">
            
                <a href="../java基础/继承多态.html">
            
                    
                    继承和多态
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.11.9" data-path="../java基础/相等判断.html">
            
                <a href="../java基础/相等判断.html">
            
                    
                    相等判断
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.11.10" data-path="../java基础/Java容器类.html">
            
                <a href="../java基础/Java容器类.html">
            
                    
                    Java容器类
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.11.11" data-path="../java基础/Java枚举.html">
            
                <a href="../java基础/Java枚举.html">
            
                    
                    Java枚举
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.11.12" data-path="../java基础/自定义异常.html">
            
                <a href="../java基础/自定义异常.html">
            
                    
                    自定义异常
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.11.13" data-path="../java基础/深度拷贝.html">
            
                <a href="../java基础/深度拷贝.html">
            
                    
                    深度拷贝
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.11.14" data-path="../java基础/泛型详解.html">
            
                <a href="../java基础/泛型详解.html">
            
                    
                    泛型详解
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.11.15" data-path="../java基础/线程详解.html">
            
                <a href="../java基础/线程详解.html">
            
                    
                    线程详解
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.11.16" data-path="../java基础/java注解.html">
            
                <a href="../java基础/java注解.html">
            
                    
                    注解详解
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.11.17" data-path="../java基础/数据解析.html">
            
                <a href="../java基础/数据解析.html">
            
                    
                    数据解析
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.11.18" data-path="../java基础/java8新特性.html">
            
                <a href="../java基础/java8新特性.html">
            
                    
                    Java8新特性
            
                </a>
            

            
        </li>
    

            </ul>
            
        </li>
    
        <li class="chapter " data-level="1.12" data-path="android零散知识.html">
            
                <a href="android零散知识.html">
            
                    
                    Android部分
            
                </a>
            

            
            <ul class="articles">
                
    
        <li class="chapter " data-level="1.12.1" data-path="基础控件使用.html">
            
                <a href="基础控件使用.html">
            
                    
                    基础控件使用
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.12.2" data-path="android零散知识.html">
            
                <a href="android零散知识.html">
            
                    
                    Android零散知识
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.12.3" data-path="android坐标体系.html">
            
                <a href="android坐标体系.html">
            
                    
                    Android坐标体系
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.12.4" data-path="APP的启动流程.html">
            
                <a href="APP的启动流程.html">
            
                    
                    APP启动流程
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.12.5" data-path="View加载流程.html">
            
                <a href="View加载流程.html">
            
                    
                    View加载流程
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.12.6" data-path="事件分发机制.html">
            
                <a href="事件分发机制.html">
            
                    
                    事件分发机制
            
                </a>
            

            
        </li>
    
        <li class="chapter active" data-level="1.12.7" data-path="控件绘制流程.html">
            
                <a href="控件绘制流程.html">
            
                    
                    控件绘制流程
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.12.8" data-path="常用shape.html">
            
                <a href="常用shape.html">
            
                    
                    常用shape
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.12.9" data-path="进程通信.html">
            
                <a href="进程通信.html">
            
                    
                    进程通信
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.12.10" data-path="../通信方式/通信方式详解.html">
            
                <a href="../通信方式/通信方式详解.html">
            
                    
                    通信方式详解
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.12.11" data-path="Binder详解.html">
            
                <a href="Binder详解.html">
            
                    
                    Binder详解
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.12.12" data-path="Handler详解.html">
            
                <a href="Handler详解.html">
            
                    
                    Handle详解
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.12.13" data-path="Fragment详解.html">
            
                <a href="Fragment详解.html">
            
                    
                    Fragment详解
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.12.14" data-path="Activity详解.html">
            
                <a href="Activity详解.html">
            
                    
                    Activity详解
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.12.15" data-path="BroadcastReceiver.html">
            
                <a href="BroadcastReceiver.html">
            
                    
                    BroadcastReceiver详解
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.12.16" data-path="Service服务.html">
            
                <a href="Service服务.html">
            
                    
                    Service详解
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.12.17" data-path="动画详解.html">
            
                <a href="动画详解.html">
            
                    
                    动画详解
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.12.18" data-path="屏幕刷新机制.html">
            
                <a href="屏幕刷新机制.html">
            
                    
                    屏幕刷新机制
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.12.19" data-path="屏幕适配.html">
            
                <a href="屏幕适配.html">
            
                    
                    屏幕适配
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.12.20" data-path="图片加载详解.html">
            
                <a href="图片加载详解.html">
            
                    
                    图片加载详解
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.12.21" data-path="WebView详解.html">
            
                <a href="WebView详解.html">
            
                    
                    WebView详解
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.12.22" data-path="沉浸式.html">
            
                <a href="沉浸式.html">
            
                    
                    沉浸式
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.12.23" data-path="相机模块.html">
            
                <a href="相机模块.html">
            
                    
                    相机模块
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.12.24" data-path="地图模块.html">
            
                <a href="地图模块.html">
            
                    
                    地图模块
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.12.25" data-path="Androidstudio插件开发.html">
            
                <a href="Androidstudio插件开发.html">
            
                    
                    Androidstudio插件开发
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.12.26" data-path="Apk插件化开发.html">
            
                <a href="Apk插件化开发.html">
            
                    
                    Apk插件化开发
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.12.27" data-path="App组件化开发.html">
            
                <a href="App组件化开发.html">
            
                    
                    App组件化开发
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.12.28" data-path="sdk开发.html">
            
                <a href="sdk开发.html">
            
                    
                    sdk开发
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.12.29" data-path="APP优化.html">
            
                <a href="APP优化.html">
            
                    
                    APP优化
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.12.30" data-path="项目参数配置.html">
            
                <a href="项目参数配置.html">
            
                    
                    项目参数配置
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.12.31" data-path="App发布.html">
            
                <a href="App发布.html">
            
                    
                    App发布
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.12.32" data-path="Android外挂.html">
            
                <a href="Android外挂.html">
            
                    
                    Android外挂
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.12.33" data-path="Android字节码插桩.html">
            
                <a href="Android字节码插桩.html">
            
                    
                    Android字节码插桩
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.12.34" data-path="智能家居.html">
            
                <a href="智能家居.html">
            
                    
                    智能家居
            
                </a>
            

            
        </li>
    

            </ul>
            
        </li>
    
        <li class="chapter " data-level="1.13" data-path="../python/python基础.html">
            
                <a href="../python/python基础.html">
            
                    
                    python部分
            
                </a>
            

            
            <ul class="articles">
                
    
        <li class="chapter " data-level="1.13.1" data-path="../python/python基础.html">
            
                <a href="../python/python基础.html">
            
                    
                    python基础
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.13.2" data-path="../python/python爬虫.html">
            
                <a href="../python/python爬虫.html">
            
                    
                    python爬虫
            
                </a>
            

            
        </li>
    

            </ul>
            
        </li>
    
        <li class="chapter " data-level="1.14" data-path="../gradle/Groovy.html">
            
                <a href="../gradle/Groovy.html">
            
                    
                    Groovy
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.15" data-path="../kotlin/kotlin部分.html">
            
                <a href="../kotlin/kotlin部分.html">
            
                    
                    kotlin部分
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.16" data-path="../flutter/flutter部分.html">
            
                <a href="../flutter/flutter部分.html">
            
                    
                    flutter部分
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.17" data-path="../native/ccpp.html">
            
                <a href="../native/ccpp.html">
            
                    
                    native部分
            
                </a>
            

            
            <ul class="articles">
                
    
        <li class="chapter " data-level="1.17.1" data-path="../native/Linux.html">
            
                <a href="../native/Linux.html">
            
                    
                    Linux
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.17.2" data-path="../native/ccpp.html">
            
                <a href="../native/ccpp.html">
            
                    
                    cCpp
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.17.3" data-path="../native/NDK.html">
            
                <a href="../native/NDK.html">
            
                    
                    NDK
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.17.4" data-path="../native/系统编译剪裁.html">
            
                <a href="../native/系统编译剪裁.html">
            
                    
                    系统编译剪裁
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.17.5" data-path="../native/音视频.html">
            
                <a href="../native/音视频.html">
            
                    
                    音视频
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.17.6" data-path="../native/音视频第三方库.html">
            
                <a href="../native/音视频第三方库.html">
            
                    
                    音视频第三方库
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.17.7" data-path="../native/相关代码.html">
            
                <a href="../native/相关代码.html">
            
                    
                    相关代码
            
                </a>
            

            
        </li>
    

            </ul>
            
        </li>
    
        <li class="chapter " data-level="1.18" data-path="../server/服务器部分.html">
            
                <a href="../server/服务器部分.html">
            
                    
                    服务器部分
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.19" data-path="../webDev/web部分.html">
            
                <a href="../webDev/web部分.html">
            
                    
                    web部分
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.20" data-path="../人工智能/人工智能相关概念.html">
            
                <a href="../人工智能/人工智能相关概念.html">
            
                    
                    人工智能
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.21" data-path="../面试真题/极飞.html">
            
                <a href="../面试真题/极飞.html">
            
                    
                    面试真题
            
                </a>
            

            
        </li>
    

    

    <li class="divider"></li>

    <li>
        <a href="https://www.gitbook.com" target="blank" class="gitbook-link">
            本书使用 GitBook 发布
        </a>
    </li>
</ul>


                </nav>
            
        
    </div>

    <div class="book-body">
        
            <div class="body-inner">
                
                    

<div class="book-header" role="navigation">
    

    <!-- Title -->
    <h1>
        <i class="fa fa-circle-o-notch fa-spin"></i>
        <a href="../.." >控件绘制流程</a>
    </h1>
</div>




                    <div class="page-wrapper" tabindex="-1" role="main">
                        <div class="page-inner">
                            
<div class="search-plus" id="book-search-results">
    <div class="search-noresults">
    
                                <section class="normal markdown-section">
                                
                                <div id="anchor-navigation-ex-navbar"><i class="fa fa-navicon"></i><ul><li><span class="title-icon "></span><a href="#ui-&#x7ED8;&#x5236;&#x7684;&#x7C7B;&#x548C;&#x51FD;&#x6570;"><b>1. </b>UI &#x7ED8;&#x5236;&#x7684;&#x7C7B;&#x548C;&#x51FD;&#x6570;</a></li><ul><li><span class="title-icon "></span><a href="#layoutinflater"><b>1.1. </b>LayoutInflater</a></li><li><span class="title-icon "></span><a href="#measurespec"><b>1.2. </b>MeasureSpec</a></li><li><span class="title-icon "></span><a href="#onmeasure-&#x6D4B;&#x91CF;&#x81EA;&#x5DF1;"><b>1.3. </b>onMeasure() &#x6D4B;&#x91CF;&#x81EA;&#x5DF1;</a></li><li><span class="title-icon "></span><a href="#onlayout-&#x6446;&#x653E;&#x3001;&#x5E03;&#x5C40;"><b>1.4. </b>onLayout() &#x6446;&#x653E;&#x3001;&#x5E03;&#x5C40;</a></li><li><span class="title-icon "></span><a href="#ondraw-&#x7ED8;&#x5236;"><b>1.5. </b>onDraw() &#x7ED8;&#x5236;</a></li><li><span class="title-icon "></span><a href="#measure"><b>1.6. </b>measure()</a></li><li><span class="title-icon "></span><a href="#getchildmeasurespec-viewgroupjava"><b>1.7. </b>getChildMeasureSpec (ViewGroup.java)</a></li><li><span class="title-icon "></span><a href="#layout"><b>1.8. </b>layout()</a></li><li><span class="title-icon "></span><a href="#setmeasureddimension"><b>1.9. </b>setMeasuredDimension()</a></li><li><span class="title-icon "></span><a href="#onsizechanged"><b>1.10. </b>onSizeChanged()</a></li><li><span class="title-icon "></span><a href="#dispatchdraw"><b>1.11. </b>dispatchDraw()</a></li><li><span class="title-icon "></span><a href="#invalidate-&#x3001;postinvalidate"><b>1.12. </b>invalidate() &#x3001;postInvalidate()</a></li><li><span class="title-icon "></span><a href="#requestlayout"><b>1.13. </b>requestLayout()</a></li><li><span class="title-icon "></span><a href="#setwillnotdraw-"><b>1.14. </b>setWillNotDraw( )</a></li><li><span class="title-icon "></span><a href="#onfinishinflate"><b>1.15. </b>onFinishInflate</a></li></ul><li><span class="title-icon "></span><a href="#&#x63D0;&#x95EE;"><b>2. </b>&#x63D0;&#x95EE;</a></li><ul><li><span class="title-icon "></span><a href="#&#x81EA;&#x5B9A;&#x4E49;&#x63A7;&#x4EF6;-xml-&#x4E2D;&#x8BBE;&#x7F6E;-wrapcontent&#x4E0E;matchparent-&#x4E3A;&#x4EC0;&#x4E48;&#x6548;&#x679C;&#x662F;&#x4E00;&#x6837;&#x7684;"><b>2.1. </b>&#x81EA;&#x5B9A;&#x4E49;&#x63A7;&#x4EF6; xml &#x4E2D;&#x8BBE;&#x7F6E; &quot;wrap_content&quot;&#x4E0E;&quot;match_parent&quot; &#x4E3A;&#x4EC0;&#x4E48;&#x6548;&#x679C;&#x662F;&#x4E00;&#x6837;&#x7684;</a></li><li><span class="title-icon "></span><a href="#&#x5982;&#x4F55;&#x89E6;&#x53D1;&#x91CD;&#x65B0;&#x7ED8;&#x5236;"><b>2.2. </b>&#x5982;&#x4F55;&#x89E6;&#x53D1;&#x91CD;&#x65B0;&#x7ED8;&#x5236;</a></li><li><span class="title-icon "></span><a href="#&#x9996;&#x6B21;-view-&#x7684;&#x7ED8;&#x5236;&#x6D41;&#x7A0B;&#x662F;&#x5728;&#x4EC0;&#x4E48;&#x65F6;&#x5019;&#x89E6;&#x53D1;&#x7684;"><b>2.3. </b>&#x9996;&#x6B21; View &#x7684;&#x7ED8;&#x5236;&#x6D41;&#x7A0B;&#x662F;&#x5728;&#x4EC0;&#x4E48;&#x65F6;&#x5019;&#x89E6;&#x53D1;&#x7684;</a></li><li><span class="title-icon "></span><a href="#&#x5982;&#x4F55;&#x83B7;&#x53D6;-&#x81EA;&#x5B9A;&#x4E49;&#x63A7;&#x4EF6;&#x7684;&#x5BBD;&#x9AD8;"><b>2.4. </b>&#x5982;&#x4F55;&#x83B7;&#x53D6; &#x81EA;&#x5B9A;&#x4E49;&#x63A7;&#x4EF6;&#x7684;&#x5BBD;&#x9AD8;</a></li><li><span class="title-icon "></span><a href="#getwidth-&#x4E0E;-getmeasuredwidth-&#x7684;&#x533A;&#x522B;"><b>2.5. </b>getWidth() &#x4E0E; getMeasuredWidth() &#x7684;&#x533A;&#x522B;</a></li><li><span class="title-icon "></span><a href="#window-&#x5C3A;&#x5BF8;&#x6D4B;&#x91CF;&#x6D41;&#x7A0B;"><b>2.6. </b>Window &#x5C3A;&#x5BF8;&#x6D4B;&#x91CF;&#x6D41;&#x7A0B;</a></li><li><span class="title-icon "></span><a href="#&#x6BCF;&#x6B21;-performmeasure-&#x4E00;&#x5B9A;&#x80FD;&#x591F;&#x89E6;&#x53D1;&#x6267;&#x884C;onmeasure&#x5417;&#xFF1F;&#x4F1A;&#x3002;"><b>2.7. </b>&#x6BCF;&#x6B21; performMeasure() &#x4E00;&#x5B9A;&#x80FD;&#x591F;&#x89E6;&#x53D1;&#x6267;&#x884C;onMeasure()&#x5417;&#xFF1F;&#x4F1A;&#x3002;</a></li><li><span class="title-icon "></span><a href="#&#x4E3A;&#x4EC0;&#x4E48;&#x4F1A;&#x591A;&#x6B21;&#x8C03;&#x7528;-onmeasure-&#x81F3;&#x5C11;2&#x6B21;"><b>2.8. </b>&#x4E3A;&#x4EC0;&#x4E48;&#x4F1A;&#x591A;&#x6B21;&#x8C03;&#x7528; onMeasure() ,&#x81F3;&#x5C11;2&#x6B21;</a></li><li><span class="title-icon "></span><a href="#&#x4E3A;&#x4EC0;&#x4E48;&#x4F1A;&#x591A;&#x6B21;&#x8C03;&#x7528;--onlayout"><b>2.9. </b>&#x4E3A;&#x4EC0;&#x4E48;&#x4F1A;&#x591A;&#x6B21;&#x8C03;&#x7528;  onLayout()</a></li></ul><li><span class="title-icon "></span><a href="#&#x81EA;&#x5B9A;&#x4E49;&#x63A7;&#x4EF6;"><b>3. </b>&#x81EA;&#x5B9A;&#x4E49;&#x63A7;&#x4EF6;</a></li><ul><li><span class="title-icon "></span><a href="#&#x81EA;&#x5B9A;&#x4E49;view&#x7684;&#x610F;&#x4E49;"><b>3.1. </b>&#x81EA;&#x5B9A;&#x4E49;View&#x7684;&#x610F;&#x4E49;</a></li><li><span class="title-icon "></span><a href="#android&#x81EA;&#x5B9A;&#x4E49;view&#x7C7B;&#x578B;"><b>3.2. </b>Android&#x81EA;&#x5B9A;&#x4E49;View&#x7C7B;&#x578B;</a></li><ul><li><span class="title-icon "></span><a href="#1&#x3001;&#x7EC4;&#x5408;&#x63A7;&#x4EF6;"><b>3.2.1. </b>1&#x3001;&#x7EC4;&#x5408;&#x63A7;&#x4EF6;</a></li><li><span class="title-icon "></span><a href="#2&#x3001;&#x5B8C;&#x5168;&#x81EA;&#x5B9A;&#x4E49;&#x63A7;&#x4EF6;"><b>3.2.2. </b>2&#x3001;&#x5B8C;&#x5168;&#x81EA;&#x5B9A;&#x4E49;&#x63A7;&#x4EF6;</a></li></ul><li><span class="title-icon "></span><a href="#view&#x81EA;&#x5B9A;&#x4E49;&#x5C5E;&#x6027;"><b>3.3. </b>View&#x81EA;&#x5B9A;&#x4E49;&#x5C5E;&#x6027;</a></li><li><span class="title-icon "></span><a href="#&#x52A8;&#x6001;&#x4FEE;&#x6539;&#x9AD8;&#x5EA6;"><b>3.4. </b>&#x52A8;&#x6001;&#x4FEE;&#x6539;&#x9AD8;&#x5EA6;</a></li></ul><li><span class="title-icon "></span><a href="#&#x6587;&#x5B57;&#x7ED8;&#x5236;"><b>4. </b>&#x6587;&#x5B57;&#x7ED8;&#x5236;</a></li><ul><li><span class="title-icon "></span><a href="#&#x6587;&#x5B57;&#x5BBD;&#x5EA6;"><b>4.1. </b>&#x6587;&#x5B57;&#x5BBD;&#x5EA6;</a></li><li><span class="title-icon "></span><a href="#&#x6587;&#x5B57;&#x9AD8;&#x5EA6;"><b>4.2. </b>&#x6587;&#x5B57;&#x9AD8;&#x5EA6;</a></li><li><span class="title-icon "></span><a href="#&#x5B57;&#x7B26;&#x95F4;&#x8DDD;"><b>4.3. </b>&#x5B57;&#x7B26;&#x95F4;&#x8DDD;</a></li><li><span class="title-icon "></span><a href="#drawtext-&#x57FA;&#x51C6;&#x70B9;"><b>4.4. </b>drawText() &#x57FA;&#x51C6;&#x70B9;</a></li><li><span class="title-icon "></span><a href="#fontmetrics"><b>4.5. </b>FontMetrics</a></li><li><span class="title-icon "></span><a href="#&#x77E9;&#x5F62;&#x4E2D;&#x6587;&#x5B57;&#x5C45;&#x4E2D;"><b>4.6. </b>&#x77E9;&#x5F62;&#x4E2D;&#x6587;&#x5B57;&#x5C45;&#x4E2D;</a></li></ul><li><span class="title-icon "></span><a href="#&#x5706;&#x89D2;&#x56FE;&#x7247;"><b>5. </b>&#x5706;&#x89D2;&#x56FE;&#x7247;</a></li><ul><li><span class="title-icon "></span><a href="#&#x901A;&#x8FC7;-paintsetxfermode-&#x7ED8;&#x5236;-&#x4F20;&#x7EDF;&#x65B9;&#x6CD5;"><b>5.1. </b>&#x901A;&#x8FC7; paint.setXfermode &#x7ED8;&#x5236;( &#x4F20;&#x7EDF;&#x65B9;&#x6CD5;)</a></li><ul><li><span class="title-icon "></span><a href="#mask-&#x5B9E;&#x73B0;&#x5706;&#x89D2;&#x6548;&#x679C;"><b>5.1.1. </b>mask &#x5B9E;&#x73B0;&#x5706;&#x89D2;&#x6548;&#x679C;</a></li></ul><li><span class="title-icon "></span><a href="#&#x901A;&#x8FC7;-bitmapshader-&#x7ED8;&#x5236;&#x5706;&#x89D2;"><b>5.2. </b>&#x901A;&#x8FC7; BitmapShader &#x7ED8;&#x5236;&#x5706;&#x89D2;</a></li><li><span class="title-icon "></span><a href="#&#x901A;&#x8FC7;-canvasclippath-&#x7ED8;&#x5236;&#x5706;&#x89D2;"><b>5.3. </b>&#x901A;&#x8FC7; canvas.clipPath &#x7ED8;&#x5236;&#x5706;&#x89D2;</a></li><li><span class="title-icon "></span><a href="#&#x901A;&#x8FC7;-viewoutlineprovider-&#x7ED8;&#x5236;-&#x652F;&#x6301;&#x4EFB;&#x4F55;-view-"><b>5.4. </b>&#x901A;&#x8FC7; ViewOutlineProvider &#x7ED8;&#x5236; (&#x652F;&#x6301;&#x4EFB;&#x4F55; View )</a></li><li><span class="title-icon "></span><a href="#&#x901A;&#x8FC7;-shapeableimageview-&#x7ED8;&#x5236;-&#x63A8;&#x8350;"><b>5.5. </b>&#x901A;&#x8FC7; ShapeableImageView &#x7ED8;&#x5236; (&#x63A8;&#x8350;)</a></li><li><span class="title-icon "></span><a href="#glide-&#x5B9E;&#x73B0;&#x5706;&#x89D2;"><b>5.6. </b>Glide &#x5B9E;&#x73B0;&#x5706;&#x89D2;</a></li><li><span class="title-icon "></span><a href="#&#x5706;&#x89D2;&#x77E9;&#x5F62;"><b>5.7. </b>&#x5706;&#x89D2;&#x77E9;&#x5F62;</a></li></ul><li><span class="title-icon "></span><a href="#&#x5706;&#x89D2;&#x77E9;&#x5F62;&#x80CC;&#x666F;--roundrectshape"><b>6. </b>&#x5706;&#x89D2;&#x77E9;&#x5F62;&#x80CC;&#x666F;  RoundRectShape</a></li><li><span class="title-icon "></span><a href="#&#x81EA;&#x5B9A;&#x4E49;&#x63A7;&#x4EF6;&#x793A;&#x4F8B;"><b>7. </b>&#x81EA;&#x5B9A;&#x4E49;&#x63A7;&#x4EF6;&#x793A;&#x4F8B;</a></li><ul><li><span class="title-icon "></span><a href="#&#x5206;&#x8D1D;&#x6CE2;&#x5F62;&#x56FE;"><b>7.1. </b>&#x5206;&#x8D1D;&#x6CE2;&#x5F62;&#x56FE;</a></li><li><span class="title-icon "></span><a href="#&#x7011;&#x5E03;&#x6D41;"><b>7.2. </b>&#x7011;&#x5E03;&#x6D41;</a></li><li><span class="title-icon "></span><a href="#&#x624B;&#x52BF;&#x63A7;&#x4EF6;"><b>7.3. </b>&#x624B;&#x52BF;&#x63A7;&#x4EF6;</a></li><li><span class="title-icon "></span><a href="#&#x4E5D;&#x5BAB;&#x683C;"><b>7.4. </b>&#x4E5D;&#x5BAB;&#x683C;</a></li><li><span class="title-icon "></span><a href="#&#x81EA;&#x5B9A;&#x4E49;&#x65E5;&#x5386;&#x63A7;&#x4EF6;"><b>7.5. </b>&#x81EA;&#x5B9A;&#x4E49;&#x65E5;&#x5386;&#x63A7;&#x4EF6;</a></li><li><span class="title-icon "></span><a href="#&#x52A0;&#x8F7D;&#x7B49;&#x5F85;&#x6846;-&#x3001;&#x83CA;&#x82B1;&#x7B49;&#x5F85;"><b>7.6. </b>&#x52A0;&#x8F7D;&#x7B49;&#x5F85;&#x6846; &#x3001;&#x83CA;&#x82B1;&#x7B49;&#x5F85;</a></li><li><span class="title-icon "></span><a href="#mpandroidchart-&#x56FE;&#x8868;&#x7ED8;&#x5236;"><b>7.7. </b>MPAndroidChart &#x56FE;&#x8868;&#x7ED8;&#x5236;</a></li></ul></ul></div><a href="#ui-&#x7ED8;&#x5236;&#x7684;&#x7C7B;&#x548C;&#x51FD;&#x6570;" id="anchorNavigationExGoTop"><i class="fa fa-arrow-up"></i></a><h1 id="ui-&#x7ED8;&#x5236;&#x7684;&#x7C7B;&#x548C;&#x51FD;&#x6570;"><a name="ui-&#x7ED8;&#x5236;&#x7684;&#x7C7B;&#x548C;&#x51FD;&#x6570;" class="anchor-navigation-ex-anchor" href="#ui-&#x7ED8;&#x5236;&#x7684;&#x7C7B;&#x548C;&#x51FD;&#x6570;"><i class="fa fa-link" aria-hidden="true"></i></a>1. UI &#x7ED8;&#x5236;&#x7684;&#x7C7B;&#x548C;&#x51FD;&#x6570;</h1>
<h2 id="layoutinflater"><a name="layoutinflater" class="anchor-navigation-ex-anchor" href="#layoutinflater"><i class="fa fa-link" aria-hidden="true"></i></a>1.1. LayoutInflater</h2>
<p>&#x5B83;&#x7684;&#x4F5C;&#x7528;&#x7C7B;&#x4F3C;&#x4E8E; findViewById(),&#x4E0D;&#x540C;&#x70B9;&#x662F;LayoutInflater&#x662F;&#x7528;&#x6765;&#x627E; layout &#x4E0B;xml&#x5E03;&#x5C40;&#x6587;&#x4EF6;&#xFF0C;&#x5E76;&#x4E14;&#x5B9E;&#x4F8B;&#x5316;&#x3002;
&#x800C;findViewById() &#x662F;&#x627E;&#x5177;&#x4F53;xml&#x4E0B;&#x7684;&#x5177;&#x4F53;&#x63A7;&#x4EF6;&#x3002;</p>
<pre><code class="lang-text">LayoutInflater inflater1 = activity.getLayoutInflater();
LayoutInflater inflater2 = LayoutInflater.from(this);
LayoutInflater inflater3 = (LayoutInflater)activity.getSystemService(LAYOUT_INFLATER_SERVICE);

// XmlPullParser parser, ViewGroup root, boolean attachToRoot
// &#x53C2;&#x6570;&#x610F;&#x4E49;&#xFF1A;parser :R.layout.abc , root :root&#x5E03;&#x5C40;   attachToRoot :&#x662F;&#x5426;&#x52A0;&#x5230;root&#x5E03;&#x5C40;&#x4E2D;
View itemView=inflater1.inflate(R.layout.abc, null);

&#x6CE8;&#x610F;&#xFF1A;
&#x901A;&#x8FC7; inflate &#x83B7;&#x5F97;&#x7684;view &#x662F;&#x83B7;&#x53D6;&#x5230;&#x7684;&#x957F;&#x5BBD;&#x90FD;&#x662F;&#x4E3A;0 &#x3002;
// itemView.getWidth() &#x3001;itemView.getHeight() &#x90FD;&#x4F1A;&#x4E3A;0

&#x4E3A;&#x4E86;&#x80FD;&#x83B7;&#x5F97;&#x957F;&#x5BBD;&#xFF0C;&#x6211;&#x76EE;&#x524D;&#x91C7;&#x7528;&#x7684;&#x662F;&#x5982;&#x4E0B;&#x65B9;&#x5F0F; &#xFF1A;
&#x5C06;&#x8FD9;&#x4E2A;&#x5E03;&#x5C40;&#x653E;&#x5230;&#x542F;&#x52A8;&#x9875;&#x4E0B; &#xFF0C;&#x901A;&#x8FC7; findViewById &#x7684;&#x65B9;&#x5F0F;&#x83B7;&#x53D6;&#x5230;&#x540E; &#x4FDD;&#x5B58;&#x8D77;&#x6765;&#x7ED9;&#x5176;&#x4ED6;&#x7528; &#x3002;
</code></pre>
<h2 id="measurespec"><a name="measurespec" class="anchor-navigation-ex-anchor" href="#measurespec"><i class="fa fa-link" aria-hidden="true"></i></a>1.2. MeasureSpec</h2>
<pre><code class="lang-text">MeasureSpec &#x901A;&#x8FC7;&#x4E00;&#x4E2A;int&#x6570;&#x503C; (widthMeasureSpec &#x3001;heightMeasureSpec) &#x4FDD;&#x5B58;&#x201C;&#x6A21;&#x5F0F;&#x201D;&#x548C;&#x201C;&#x5927;&#x5C0F;&#x201D;&#xFF0C;
&#x524D;2&#x4F4D;&#x8868;&#x793A;&#x201C;&#x5927;&#x5C0F;&#x7684;&#x6A21;&#x5F0F;&#x201D; &#xFF0C;&#x540E;30bit&#x8868;&#x793A; &#x201C;&#x5C3A;&#x5BF8;&#x5927;&#x5C0F;&#x201D;
int mode=MeasureSpec.getMode(widthMeasureSpec);
int size=MeasureSpec.getSize(widthMeasureSpec);

//MeasureSpec.AT_MOST
&#x7236;&#x5BB9;&#x5668;&#x7ED9;&#x5B50;View&#x4E00;&#x4E2A;&#x6781;&#x9650;&#x503C;&#xFF0C;&#x6700;&#x591A;&#x53EF;&#x4EE5;&#x591A;&#x5C11;&#x3002;&#x8FD9;&#x4E2A;&#x503C;&#x53EF;&#x4EE5;&#x7528; getSize()&#x83B7;&#x53D6;&#x5230;
int widthSize =MeasureSpec.getSize(widthMeasureSpec)

//MeasureSpec.EXACTLY ,&#x7528;&#x7684;&#x8F83;&#x591A;
&#x7236;&#x5BB9;&#x5668;&#x7ED9;&#x5B50;View&#x6307;&#x5B9A;&#x4E86;&#x4E00;&#x4E2A;&#x660E;&#x786E;&#x7684;&#x503C;&#xFF0C;&#x8FD9;&#x4E2A;&#x503C;&#x53EF;&#x4EE5;&#x7528; getSize() &#x83B7;&#x53D6;&#x5230;
int widthSize =MeasureSpec.getSize(widthMeasureSpec)

//MeasureSpec.UNSPECIFIED ,&#x5F88;&#x5C11;&#x7528;
&#x7236;&#x5BB9;&#x5668;&#x4E0D;&#x7EA6;&#x675F;&#x5B50;View&#x7684;&#x5927;&#x5C0F;&#x3002;
</code></pre>
<h2 id="onmeasure-&#x6D4B;&#x91CF;&#x81EA;&#x5DF1;"><a name="onmeasure-&#x6D4B;&#x91CF;&#x81EA;&#x5DF1;" class="anchor-navigation-ex-anchor" href="#onmeasure-&#x6D4B;&#x91CF;&#x81EA;&#x5DF1;"><i class="fa fa-link" aria-hidden="true"></i></a>1.3. onMeasure() &#x6D4B;&#x91CF;&#x81EA;&#x5DF1;</h2>
<pre><code class="lang-text">&#x6D4B;&#x91CF; View &#x7684;&#x5927;&#x5C0F; &#xFF0C;&#x51B3;&#x5B9A;&#x4E86; view &#x672C;&#x8EAB;&#x7684;&#x5927;&#x5C0F;&#x3002;
&#x5B50;View &#x6839;&#x636E;&#x7236;&#x5BB9;&#x5668;&#x4F20;&#x5165;&#x7684;&#x5BF9;&#x81EA;&#x5DF1;&#x7684;&#x7EA6;&#x675F;&#x53C2;&#x6570;&#xFF0C;&#x6839;&#x636E;&#x81EA;&#x5DF1;&#x7684;&#x5B9E;&#x9645;&#x60C5;&#x51B5;&#x8FDB;&#x884C;&#x4FEE;&#x6539;&#x6700;&#x7EC8;&#x786E;&#x8BA4;&#x540E;
&#x518D;&#x628A;&#x4FEE;&#x6539;&#x7ED3;&#x679C;&#x544A;&#x8BC9;&#x7236;&#x5BB9;&#x5668;&#x3002;

&#x7236;&#x5BB9;&#x5668;&#x4F20;&#x7ED9; &#x5B50;View &#x7684;&#x6A21;&#x5F0F;&#x662F; UNSPECIFIED &#x8FD8;&#x662F; AT_MOST &#xFF0C;
&#x662F;&#x6839;&#x636E; &#x5B50;View &#x5728; xml(&#x6216;&#x4EE3;&#x7801;) &#x7684;&#x914D;&#x7F6E; &#x548C; &#x7236;&#x5BB9;&#x5668;&#x81EA;&#x5DF1;&#x7684;&#x6761;&#x4EF6;&#x6765;&#x51B3;&#x5B9A;&#x7684;&#x3002;
&#x5177;&#x4F53;&#x539F;&#x7406;&#x79FB;&#x6B65;&#x9605;&#x8BFB; getChildMeasureSpec() &#x6E90;&#x7801; &#x3002;

@Override
protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
    int measureWidth = getMyViewSize(100, widthMeasureSpec);
    int measureHeight = getMyViewSize(200, heightMeasureSpec);
    setMeasuredDimension(measureWidth, measureHeight);
}
private int getMyViewSize(int defaultSize, int measureSpec) {
    int result = defaultSize;
    int specMode = MeasureSpec.getMode(measureSpec);
    int specSize = MeasureSpec.getSize(measureSpec);
    // &#x8FD9;&#x91CC;&#x7684;&#x5904;&#x7406;&#x53EA;&#x662F;&#x4E3E;&#x4F8B;&#xFF0C;&#x5B9E;&#x9645;&#x5F00;&#x53D1;&#x4E2D;&#x9700;&#x8981;&#x6839;&#x636E;&#x81EA;&#x5DF1;&#x7684;&#x63A7;&#x4EF6;&#x7C7B;&#x578B;&#x4FEE;&#x6539;&#x65B9;&#x6848;
    switch (specMode) {
        case MeasureSpec.UNSPECIFIED:
            result = defaultSize;
            break;
        case MeasureSpec.AT_MOST:
            result = defaultSize;
            break;
        case MeasureSpec.EXACTLY:
            result = specSize;
            break;
    }
    return result;
}
</code></pre>
<h2 id="onlayout-&#x6446;&#x653E;&#x3001;&#x5E03;&#x5C40;"><a name="onlayout-&#x6446;&#x653E;&#x3001;&#x5E03;&#x5C40;" class="anchor-navigation-ex-anchor" href="#onlayout-&#x6446;&#x653E;&#x3001;&#x5E03;&#x5C40;"><i class="fa fa-link" aria-hidden="true"></i></a>1.4. onLayout() &#x6446;&#x653E;&#x3001;&#x5E03;&#x5C40;</h2>
<pre><code class="lang-text">&#x7ED3;&#x5408; measure()  &#x51B3;&#x5B9A; View &#x81EA;&#x5DF1; &#x5728; ViewGroup&#x4E2D;&#x7684;&#x4F4D;&#x7F6E;&#x5982;&#x4F55;&#x3002;
&#x5728; ViewGroup &#x4E2D;&#x662F; abstract, &#x5FC5;&#x987B;&#x91CD;&#x5199;&#x3002; 
&#x5728;View&#x4E2D;&#x662F;&#x7A7A;&#x51FD;&#x6570;&#xFF0C;&#x4E00;&#x822C;&#x4E0D;&#x7528;&#x91CD;&#x5199;&#x3002; 

protected void onLayout(boolean boo, int l, int t, int r, int b) {
    for (int j=0;j&lt;getChildCount();j++){
        View view = getChildAt(j);
        //  &#x91CD;&#x65B0;&#x5E03;&#x5C40;&#x5B50;View
        view.layout(l + padding,t  + padding,l + width, t + width);
    }
}
</code></pre>
<h2 id="ondraw-&#x7ED8;&#x5236;"><a name="ondraw-&#x7ED8;&#x5236;" class="anchor-navigation-ex-anchor" href="#ondraw-&#x7ED8;&#x5236;"><i class="fa fa-link" aria-hidden="true"></i></a>1.5. onDraw() &#x7ED8;&#x5236;</h2>
<pre><code class="lang-text">&#x51B3;&#x5B9A;&#x5982;&#x4F55;&#x7ED8;&#x5236;&#x8FD9;&#x4E2A; View &#x3002;
</code></pre>
<h2 id="measure"><a name="measure" class="anchor-navigation-ex-anchor" href="#measure"><i class="fa fa-link" aria-hidden="true"></i></a>1.6. measure()</h2>
<pre><code class="lang-text">// &#x6D4B;&#x91CF;&#x5165;&#x53E3;&#xFF0C;&#x4E00;&#x822C;&#x4E0D;&#x7528;&#x91CD;&#x5199;&#x3002;
public final void measure(int widthMeasureSpec, int heightMeasureSpec){ }
</code></pre>
<h2 id="getchildmeasurespec-viewgroupjava"><a name="getchildmeasurespec-viewgroupjava" class="anchor-navigation-ex-anchor" href="#getchildmeasurespec-viewgroupjava"><i class="fa fa-link" aria-hidden="true"></i></a>1.7. getChildMeasureSpec (ViewGroup.java)</h2>
<pre><code class="lang-text">&#x7236;&#x5BB9;&#x5668;&#x5BF9; &#x5B50;View&#x7684;&#x6D4B;&#x91CF;&#x3002;
ViewGroup.java &#x4E2D;&#x7684;&#x6E90;&#x7801;&#x9605;&#x8BFB;
public static int getChildMeasureSpec(int spec, int padding, int childDimension) {
    // childDimension &#x4E3A; layout_width/layout_height &#x7684;&#x503C;&#xFF0C;&#x7528;&#x6574;&#x6570;&#x8868;&#x793A;
    int specMode = MeasureSpec.getMode(spec);
    int specSize = MeasureSpec.getSize(spec);
    // padding &#x4E3A;&#x5176;&#x4ED6;&#x5DF2;&#x4F7F;&#x7528;&#x7684;&#x7A7A;&#x95F4;&#xFF0C;&#x4E5F;&#x5C31;&#x662F;&#x8BF4;&#x8BE5;&#x5E03;&#x5C40;&#x91CC;&#x5DF2;&#x4F7F;&#x7528;&#x4E86;padding&#xFF0C;
    //&#x8FD9;&#x90E8;&#x5206;&#x5DF2;&#x7ECF;&#x4E0D;&#x80FD;&#x5206;&#x914D;&#x4E86;&#xFF0C;&#x53EA;&#x80FD;&#x5206;&#x914D;&#x4F59;&#x4E0B;&#x7684;&#x7A7A;&#x95F4;&#x4E86;&#x3002;
    int size = Math.max(0, specSize - padding);
    int resultSize = 0;
    int resultMode = 0;
    switch (specMode) {
        //&#x7236;&#x5E03;&#x5C40;&#x7684;&#x6D4B;&#x91CF;&#x6A21;&#x5F0F;&#x662F;&#x786E;&#x5207;&#x7684;
        case MeasureSpec.EXACTLY:
            if (childDimension &gt;= 0) {
                // &#x5B50;&#x5E03;&#x5C40;&#x58F0;&#x660E;&#x4E86;&#x81EA;&#x5DF1;&#x60F3;&#x8981;&#x786E;&#x5207;&#x7684;&#x5C3A;&#x5BF8;&#xFF1A;childDimension&#xFF0C;&#x90A3;&#x4E48;&#x7236;&#x5E03;&#x5C40;&#x5C31;&#x7B54;&#x5E94;&#x5B83;&#xFF0C;
                //&#x5E76;&#x4E14;&#x5B50;&#x5E03;&#x5C40;&#x7684;&#x6D4B;&#x91CF;&#x6A21;&#x5F0F;&#x4E3A;&#x786E;&#x5207;&#x7684;
                resultSize = childDimension;
                resultMode = MeasureSpec.EXACTLY;
            } else if (childDimension == ViewGroup.LayoutParams.MATCH_PARENT) {
                //&#x5B50;&#x5E03;&#x5C40;&#x58F0;&#x660E;&#x4E86;&#x81EA;&#x5DF1;&#x60F3;&#x8981;&#x7684;&#x5C3A;&#x5BF8;&#x662F;&#x4E0E;&#x7236;&#x5E03;&#x5C40;&#x4E00;&#x6837;&#x5927;&#xFF0C;&#x90A3;&#x4E48;&#x7236;&#x5E03;&#x5C40;&#x5C31;&#x7B54;&#x5E94;&#x5B83;&#xFF0C;&#x5C06;&#x5269;&#x4E0B;&#x7684;&#x5C3A;&#x5BF8;&#x7ED9;&#x5B83;
                // &#x56E0;&#x4E3A;&#x7236;&#x5E03;&#x5C40;&#x662F;&#x786E;&#x5207;&#x7684;&#x5C3A;&#x5BF8;&#xFF0C;&#x56E0;&#x6B64;&#x5B50;&#x5E03;&#x5C40;&#x7684;&#x6D4B;&#x91CF;&#x6A21;&#x5F0F;&#x4E3A;&#x786E;&#x5207;&#x7684;
                resultSize = size;
                resultMode = MeasureSpec.EXACTLY;
            } else if (childDimension == ViewGroup.LayoutParams.WRAP_CONTENT) {
                //&#x5B50;&#x5E03;&#x5C40;&#x58F0;&#x660E;&#x4E86;&#x81EA;&#x5DF1;&#x60F3;&#x8981;&#x7684;&#x5C3A;&#x5BF8;&#x662F;&#x5305;&#x62EC;&#x5185;&#x5BB9;&#xFF0C;&#x5B83;&#x81EA;&#x5DF1;&#x5F53;&#x524D;&#x4E5F;&#x4E0D;&#x77E5;&#x9053;&#x5177;&#x4F53;&#x8981;&#x591A;&#x5927;&#xFF0C;
                //&#x90A3;&#x4E48;&#x7236;&#x5E03;&#x5C40;&#x5C31;&#x7B54;&#x5E94;&#x5B83;&#xFF0C;&#x5C06;&#x5269;&#x4E0B;&#x7684;&#x5C3A;&#x5BF8;&#x7ED9;&#x5B83;
                //&#x56E0;&#x4E3A;&#x4E0D;&#x77E5;&#x9053;&#x81EA;&#x5DF1;&#x5177;&#x4F53;&#x591A;&#x5927;&#xFF0C;&#x56E0;&#x6B64;&#x5B50;&#x5E03;&#x5C40;&#x6D4B;&#x91CF;&#x6A21;&#x5F0F;&#x4E3A;AT_MOST(&#x6700;&#x591A;&#xFF09;
                resultSize = size;
                resultMode = MeasureSpec.AT_MOST;
            }
            break;

        case MeasureSpec.AT_MOST:
            if (childDimension &gt;= 0) {
                //&#x4E0E;&#x4E0A;&#x9762;&#x4E00;&#x81F4;
                resultSize = childDimension;
                resultMode = MeasureSpec.EXACTLY;
            } else if (childDimension == ViewGroup.LayoutParams.MATCH_PARENT) {
                //&#x867D;&#x7136;&#x5B50;&#x5E03;&#x5C40;&#x58F0;&#x660E;&#x4E86;&#x4E0E;&#x7236;&#x5E03;&#x5C40;&#x4E00;&#x6837;&#x5927;&#xFF0C;&#x4F46;&#x662F;&#x7236;&#x5E03;&#x5C40;&#x662F;AT_MOST&#xFF0C;&#x7236;&#x5E03;&#x5C40;&#x4E5F;&#x4E0D;&#x77E5;&#x9053;&#x81EA;&#x5DF1;&#x6709;&#x591A;&#x5927;&#xFF0C;
                //&#x56E0;&#x6B64;&#x7ED9;&#x5B50;&#x5E03;&#x5C40;&#x7684;&#x6D4B;&#x91CF;&#x6A21;&#x5F0F;&#x662F;AT_MOST(&#x6700;&#x591A;&#xFF09;
                resultSize = size;
                resultMode = MeasureSpec.AT_MOST;
            } else if (childDimension == ViewGroup.LayoutParams.WRAP_CONTENT) {
                //&#x4E0E;&#x4E0A;&#x9762;&#x4E00;&#x81F4;
                resultSize = size;
                resultMode = MeasureSpec.AT_MOST;
            }
            break;

        // Parent asked to see how big we want to be
        case MeasureSpec.UNSPECIFIED:
            ...
            break;
    }
    //&#x901A;&#x8FC7;MeasureSpec &#x5C01;&#x88C5;&#x6D4B;&#x91CF;&#x6A21;&#x5F0F;&#x548C;&#x5C3A;&#x5BF8;
    return MeasureSpec.makeMeasureSpec(resultSize, resultMode);
}
</code></pre>
<h2 id="layout"><a name="layout" class="anchor-navigation-ex-anchor" href="#layout"><i class="fa fa-link" aria-hidden="true"></i></a>1.8. layout()</h2>
<p>&#x786E;&#x5B9A;View&#x81EA;&#x5DF1;&#x7684;&#x4F4D;&#x7F6E;&#x3002;</p>
<pre><code class="lang-text">ViewGroup&#x4E2D;&#x7684; &#x662F; final void layout &#xFF0C;&#x4E0D;&#x80FD;&#x91CD;&#x5199;&#x3002;
View&#x4E2D; public void layout &#xFF0C;&#x53EF;&#x4EE5;&#x91CD;&#x5199;&#x3002;&#x4F46;&#x662F;&#x4E00;&#x822C;&#x4E0D;&#x91CD;&#x5199;&#x3002;
&#x5728; &#x7236;&#x5BB9;&#x5668;&#x4E2D;&#x76F4;&#x63A5;&#x8BA9;&#x5B50;View&#x76F4;&#x63A5;&#x8C03;&#x7528;&#x5373;&#x53EF;&#x3002; 

for (int j=0;j&lt;getChildCount();j++){
    View view = getChildAt(j);
    view.layout(...); // &#x6CE8;&#x610F;&#x6B64;&#x5904;&#x7684; xx.layout() 
&#xFF5D;
</code></pre>
<h2 id="setmeasureddimension"><a name="setmeasureddimension" class="anchor-navigation-ex-anchor" href="#setmeasureddimension"><i class="fa fa-link" aria-hidden="true"></i></a>1.9. setMeasuredDimension()</h2>
<pre><code class="lang-text">&#x5B50;&#x63A7;&#x4EF6;&#x63A7;&#x4EF6;&#x5728; &#x81EA;&#x5DF1;&#x7684; onMeasure() &#x786E;&#x5B9A;&#x4E86;&#x81EA;&#x5DF1;&#x7684;&#x5C3A;&#x5BF8;&#x540E;&#xFF0C;&#x544A;&#x77E5;&#x7236;&#x5BB9;&#x5668;&#x3002;
&#x4E00;&#x822C;&#x5728; onMeasure() &#x4E2D;&#x8C03;&#x7528;&#x3002;
</code></pre>
<h2 id="onsizechanged"><a name="onsizechanged" class="anchor-navigation-ex-anchor" href="#onsizechanged"><i class="fa fa-link" aria-hidden="true"></i></a>1.10. onSizeChanged()</h2>
<p>&#x8BE5;&#x65B9;&#x6CD5;&#x5728;&#x5F53;&#x524D;View&#x5C3A;&#x5BF8;&#x53D8;&#x5316;&#x65F6;&#x88AB;&#x8C03;&#x7528; &#x3002;
&#x53EF;&#x4EE5;&#x5728;&#x8FD9;&#x91CC;&#x91CD;&#x65B0;&#x83B7;&#x53D6;view&#x7684;&#x957F;&#x5BBD;&#x7B49;&#x53C2;&#x6570;&#x3002;</p>
<pre><code class="lang-text">protected void onSizeChanged(int w, int h, int oldw, int oldh)  {
    super.onSizeChanged(w, h, oldw, oldh);
    if (w != oldw || h != oldh) {
        mHeight = h;
        mMaxOverScrollDistance = w / 2.f;
    }
}
</code></pre>
<h2 id="dispatchdraw"><a name="dispatchdraw" class="anchor-navigation-ex-anchor" href="#dispatchdraw"><i class="fa fa-link" aria-hidden="true"></i></a>1.11. dispatchDraw()</h2>
<p>&#x7ED8;&#x5236;&#x5B50;View&#x3002;</p>
<pre><code class="lang-text">View &#x6CA1;&#x6709;&#x91CD;&#x5199; dispatchDraw&#x7684;&#x5FC5;&#x8981;&#x3002;

ViewGroup &#x8C8C;&#x4F3C;&#x4E00;&#x822C;&#x4E5F;&#x4E0D;&#x7528;&#x91CD;&#x5199; dispatchDraw &#xFF0C;&#x53EA;&#x662F;&#x5728;&#x5408;&#x9002;&#x7684;&#x5730;&#x65B9;&#x8C03;&#x7528;&#x4E00;&#x4E0B;&#x81EA;&#x5DF1;&#x7684;&#x8FD9;&#x4E2A;&#x65B9;&#x6CD5;&#xFF0C;&#x4F7F;&#x5F97;&#x81EA;&#x5DF1;&#x7684;&#x5B50;View&#x90FD;&#x53BB;&#x91CD;&#x65B0;&#x7ED8;&#x5236;&#x3002;
</code></pre>
<h2 id="invalidate-&#x3001;postinvalidate"><a name="invalidate-&#x3001;postinvalidate" class="anchor-navigation-ex-anchor" href="#invalidate-&#x3001;postinvalidate"><i class="fa fa-link" aria-hidden="true"></i></a>1.12. invalidate() &#x3001;postInvalidate()</h2>
<pre><code class="lang-text">&#x90FD;&#x662F;&#x7528;&#x4E8E;&#x5237;&#x65B0;&#x754C;&#x9762;&#x3002;
invalidate  &#x5728;UI&#x7EBF;&#x7A0B;&#x8C03;&#x7528;&#x3002;
postInvalidate  &#x5728;&#x975E;UI&#x7EBF;&#x7A0B;&#x8C03;&#x7528;&#xFF0C;&#x5C06;&#x975E;UI&#x7EBF;&#x7A0B;&#x5207;&#x6362;&#x5230;UI&#x7EBF;&#x7A0B;&#xFF0C;&#x6700;&#x540E;&#x4E5F;&#x662F;&#x8C03;&#x7528;invalidate &#x3002;

&#x5728; View &#x5DF2;&#x88AB;&#x9644;&#x52A0;&#x5728; &#x5F53;&#x524D;&#x7A97;&#x53E3;&#x7684;&#x524D;&#x63D0;&#x4E0B;&#xFF0C;invalidate &#x4E00;&#x5B9A;&#x4F1A;&#x5F15;&#x8D77; onDraw &#x3002;
&#x5982;&#x679C;&#x662F; ViewGroup &#xFF0C;&#x9ED8;&#x8BA4;&#x662F;&#x8BA4;&#x4E3A;&#x4E0D;&#x9700;&#x8981;&#x91CD;&#x65B0;&#x7ED8;&#x5236;&#x7684; &#xFF0C;
&#x5982;&#x679C;&#x6CA1;&#x6709;&#x8BBE;&#x7F6E;&#x8FC7;&#x80CC;&#x666F; &#xFF0C;&#x8C03;&#x7528; invalidate &#xFF0C;viewGroup &#x7684; onDraw &#x4E0D;&#x4F1A;&#x88AB;&#x8C03;&#x7528;&#x3002;

invalidate &#x4E0D;&#x4F1A;&#x5BFC;&#x81F4; onMeasure &#x548C; onLayout &#x88AB;&#x8C03;&#x7528;&#xFF0C;&#x800C; OnDraw &#x4F1A;&#x88AB;&#x8C03;&#x7528;&#x3002;
</code></pre>
<h2 id="requestlayout"><a name="requestlayout" class="anchor-navigation-ex-anchor" href="#requestlayout"><i class="fa fa-link" aria-hidden="true"></i></a>1.13. requestLayout()</h2>
<pre><code class="lang-text">&#x5E38;&#x7528;&#x4E8E;&#x66F4;&#x65B0; &#x3002;
requestLayout &#x4F1A;&#x5BFC;&#x81F4;&#x8C03;&#x7528; measure()&#x8FC7;&#x7A0B; &#x548C; layout()&#x8FC7;&#x7A0B;&#xFF0C; 
&#x5C06;&#x4F1A;&#x6839;&#x636E;&#x6807;&#x5FD7;&#x4F4D;&#x5224;&#x65AD;&#x662F;&#x5426;&#x9700;&#x8981; onDraw&#x3002;

invalidate &#x4F1A;&#x5BFC;&#x81F4;&#x8C03;&#x7528; onDraw &#x3002;
&#x6240;&#x4EE5;&#x4E00;&#x822C;&#x800C;&#x8A00;&#xFF0C;&#x5982;&#x679C;&#x662F;&#x7ED8;&#x5236;&#x5185;&#x5BB9;&#x53D8;&#x4E86;&#x5C31;&#x8C03;&#x7528; invalidate &#xFF0C; 
&#x5982;&#x679C;&#x662F;&#x4F4D;&#x7F6E;&#x53D8;&#x4E86;&#x5C31;&#x8C03;&#x7528; requestLayout &#x3002;

requestLayout &#x4F1A;&#x5BFC;&#x81F4; onMeasure &#x548C; onLayout &#x88AB;&#x8C03;&#x7528;&#x3002;&#x4E0D;&#x4E00;&#x5B9A;&#x4F1A;&#x89E6;&#x53D1; OnDraw &#x3002;
</code></pre>
<h2 id="setwillnotdraw-"><a name="setwillnotdraw-" class="anchor-navigation-ex-anchor" href="#setwillnotdraw-"><i class="fa fa-link" aria-hidden="true"></i></a>1.14. setWillNotDraw( )</h2>
<pre><code class="lang-text">setWillNotDraw(true) // &#x8BBE;&#x7F6E;&#x540E; &#x5C31;&#x4E0D;&#x4F1A;&#x8C03;&#x7528; onDraw() &#x3002;&#x4E00;&#x822C;&#x7528;&#x6765;&#x4F18;&#x5316;GroupView
View&#x4E2D;&#x9ED8;&#x8BA4;&#x8BBE;&#x7F6E;&#x4E3A;false ,ViewGroup&#x9ED8;&#x8BA4;&#x8BBE;&#x7F6E;&#x4E3A;true &#x3002;
</code></pre>
<h2 id="onfinishinflate"><a name="onfinishinflate" class="anchor-navigation-ex-anchor" href="#onfinishinflate"><i class="fa fa-link" aria-hidden="true"></i></a>1.15. onFinishInflate</h2>
<pre><code class="lang-text">&#x5F53; XML&#x5E03;&#x5C40;&#x88AB;&#x52A0;&#x8F7D;&#x5B8C;&#x540E;&#xFF0C;&#x5C31;&#x4F1A;&#x56DE;&#x8C03;&#x8FD9;&#x4E2A;&#x65B9;&#x6CD5;&#xFF0C;&#x5728;&#x8FD9;&#x4E2A;&#x65B9;&#x6CD5;&#x4E2D;&#x6211;&#x4EEC;&#x53EF;&#x4EE5;&#x521D;&#x59CB;&#x5316;&#x63A7;&#x4EF6;&#x548C;&#x6570;&#x636E;&#x3002;
</code></pre>
<h1 id="&#x63D0;&#x95EE;"><a name="&#x63D0;&#x95EE;" class="anchor-navigation-ex-anchor" href="#&#x63D0;&#x95EE;"><i class="fa fa-link" aria-hidden="true"></i></a>2. &#x63D0;&#x95EE;</h1>
<h2 id="&#x81EA;&#x5B9A;&#x4E49;&#x63A7;&#x4EF6;-xml-&#x4E2D;&#x8BBE;&#x7F6E;-wrapcontent&#x4E0E;matchparent-&#x4E3A;&#x4EC0;&#x4E48;&#x6548;&#x679C;&#x662F;&#x4E00;&#x6837;&#x7684;"><a name="&#x81EA;&#x5B9A;&#x4E49;&#x63A7;&#x4EF6;-xml-&#x4E2D;&#x8BBE;&#x7F6E;-wrapcontent&#x4E0E;matchparent-&#x4E3A;&#x4EC0;&#x4E48;&#x6548;&#x679C;&#x662F;&#x4E00;&#x6837;&#x7684;" class="anchor-navigation-ex-anchor" href="#&#x81EA;&#x5B9A;&#x4E49;&#x63A7;&#x4EF6;-xml-&#x4E2D;&#x8BBE;&#x7F6E;-wrapcontent&#x4E0E;matchparent-&#x4E3A;&#x4EC0;&#x4E48;&#x6548;&#x679C;&#x662F;&#x4E00;&#x6837;&#x7684;"><i class="fa fa-link" aria-hidden="true"></i></a>2.1. &#x81EA;&#x5B9A;&#x4E49;&#x63A7;&#x4EF6; xml &#x4E2D;&#x8BBE;&#x7F6E; &quot;wrap_content&quot;&#x4E0E;&quot;match_parent&quot; &#x4E3A;&#x4EC0;&#x4E48;&#x6548;&#x679C;&#x662F;&#x4E00;&#x6837;&#x7684;</h2>
<pre><code class="lang-text">&#x5F53;&#x6211;&#x4EEC;&#x5206;&#x522B;&#x8BBE;&#x7F6E; layout_width=wrap_content&#x3001;layout_width=match_parent &#x65F6;&#xFF0C;
&#x7236;&#x5BB9;&#x5668;&#x4F20;&#x7ED9; &#x5B50;&#x63A7;&#x4EF6;&#x7684; &#x6A21;&#x5F0F;&#x5206;&#x522B;&#x4E3A;: AT_MOST&#x3001; EXACTLY
&#x5982;&#x679C; &#x81EA;&#x5B9A;&#x4E49;&#x63A7;&#x4EF6;&#x6CA1;&#x6709; &#x91CD;&#x5199; onMeasure() ,&#x5C31;&#x4F1A;&#x8C03;&#x7528; View.onMeasure&#x7684;&#x65B9;&#x6CD5;&#xFF0C;
&#x7136;&#x540E;&#x5728; getDefaultSize() &#x4E2D;&#x5BF9; AT_MOST &#x3001;EXACTLY &#x7684;&#x5904;&#x7406;&#x662F;&#x4E00;&#x6837;&#x7684;&#x3002;

protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
    setMeasuredDimension(getDefaultSize(getSuggestedMinimumWidth(), widthMeasureSpec),
            getDefaultSize(getSuggestedMinimumHeight(), heightMeasureSpec));
}
public static int getDefaultSize(int size, int measureSpec) {
    int result = size;
    int specMode = MeasureSpec.getMode(measureSpec);
    int specSize = MeasureSpec.getSize(measureSpec);
    switch (specMode) {
    case MeasureSpec.UNSPECIFIED:
        result = size;
        break;
    case MeasureSpec.AT_MOST:
    case MeasureSpec.EXACTLY:
        result = specSize;
        break;
    }
    return result;
}
</code></pre>
<h2 id="&#x5982;&#x4F55;&#x89E6;&#x53D1;&#x91CD;&#x65B0;&#x7ED8;&#x5236;"><a name="&#x5982;&#x4F55;&#x89E6;&#x53D1;&#x91CD;&#x65B0;&#x7ED8;&#x5236;" class="anchor-navigation-ex-anchor" href="#&#x5982;&#x4F55;&#x89E6;&#x53D1;&#x91CD;&#x65B0;&#x7ED8;&#x5236;"><i class="fa fa-link" aria-hidden="true"></i></a>2.2. &#x5982;&#x4F55;&#x89E6;&#x53D1;&#x91CD;&#x65B0;&#x7ED8;&#x5236;</h2>
<pre><code class="lang-text">invalidate() &#x3001;postInvalidate()
</code></pre>
<h2 id="&#x9996;&#x6B21;-view-&#x7684;&#x7ED8;&#x5236;&#x6D41;&#x7A0B;&#x662F;&#x5728;&#x4EC0;&#x4E48;&#x65F6;&#x5019;&#x89E6;&#x53D1;&#x7684;"><a name="&#x9996;&#x6B21;-view-&#x7684;&#x7ED8;&#x5236;&#x6D41;&#x7A0B;&#x662F;&#x5728;&#x4EC0;&#x4E48;&#x65F6;&#x5019;&#x89E6;&#x53D1;&#x7684;" class="anchor-navigation-ex-anchor" href="#&#x9996;&#x6B21;-view-&#x7684;&#x7ED8;&#x5236;&#x6D41;&#x7A0B;&#x662F;&#x5728;&#x4EC0;&#x4E48;&#x65F6;&#x5019;&#x89E6;&#x53D1;&#x7684;"><i class="fa fa-link" aria-hidden="true"></i></a>2.3. &#x9996;&#x6B21; View &#x7684;&#x7ED8;&#x5236;&#x6D41;&#x7A0B;&#x662F;&#x5728;&#x4EC0;&#x4E48;&#x65F6;&#x5019;&#x89E6;&#x53D1;&#x7684;</h2>
<pre><code class="lang-text">&#x59CB;&#x4E8E; ViewRootImpl &#x7684; performTraversals() &#x3002;
&#x6709;&#x8C03;&#x7528; performMeasure() -&gt;  performLayout() -&gt;  performDraw()
</code></pre>
<h2 id="&#x5982;&#x4F55;&#x83B7;&#x53D6;-&#x81EA;&#x5B9A;&#x4E49;&#x63A7;&#x4EF6;&#x7684;&#x5BBD;&#x9AD8;"><a name="&#x5982;&#x4F55;&#x83B7;&#x53D6;-&#x81EA;&#x5B9A;&#x4E49;&#x63A7;&#x4EF6;&#x7684;&#x5BBD;&#x9AD8;" class="anchor-navigation-ex-anchor" href="#&#x5982;&#x4F55;&#x83B7;&#x53D6;-&#x81EA;&#x5B9A;&#x4E49;&#x63A7;&#x4EF6;&#x7684;&#x5BBD;&#x9AD8;"><i class="fa fa-link" aria-hidden="true"></i></a>2.4. &#x5982;&#x4F55;&#x83B7;&#x53D6; &#x81EA;&#x5B9A;&#x4E49;&#x63A7;&#x4EF6;&#x7684;&#x5BBD;&#x9AD8;</h2>
<pre><code class="lang-text">1&#x3001;addOnGlobalLayoutListener
private void test(){
    final View thisView = this;
    this.getViewTreeObserver().addOnGlobalLayoutListener(new ViewTreeObserver.OnGlobalLayoutListener() {
        @Override
        public void onGlobalLayout() {
            thisView.getViewTreeObserver().removeOnGlobalLayoutListener(this);
            int height = thisView.getMeasuredHeight();
            int width = thisView.getMeasuredHeight() ;
        }
    });
}

2&#x3001;view.post() &#x3001; view.postDelayed() 
view.post() &#x65B9;&#x6CD5;&#x5728;&#x6574;&#x4E2A;view&#x6811;&#x7684; performMeasure &#x3001; performLayout &#x3001;performDraw&#x6267;&#x884C;&#x5B8C;&#x540E;&#xFF0C;
&#x624D;&#x88AB;&#x4E3B;&#x7EBF;&#x7A0B;&#x8F6E;&#x8BE2;&#x5230;&#xFF0C;&#x624D;&#x5F97;&#x5230;&#x6267;&#x884C;&#x3002;
&#x56E0;&#x6B64;&#x6574;&#x4E2A;View&#x6811;&#x90FD;&#x5B8C;&#x6210;&#x4E86;&#x6D4B;&#x91CF;&#xFF0C;&#x5E03;&#x5C40;&#xFF0C;&#x7ED8;&#x5236;&#x3002;
&#x6240;&#x4EE5;&#x53EF;&#x4EE5;&#x62FF;&#x5230;&#x5BBD;&#x9AD8;&#x4FE1;&#x606F;&#x3002;
</code></pre>
<h2 id="getwidth-&#x4E0E;-getmeasuredwidth-&#x7684;&#x533A;&#x522B;"><a name="getwidth-&#x4E0E;-getmeasuredwidth-&#x7684;&#x533A;&#x522B;" class="anchor-navigation-ex-anchor" href="#getwidth-&#x4E0E;-getmeasuredwidth-&#x7684;&#x533A;&#x522B;"><i class="fa fa-link" aria-hidden="true"></i></a>2.5. getWidth() &#x4E0E; getMeasuredWidth() &#x7684;&#x533A;&#x522B;</h2>
<pre><code class="lang-text">getMeasuredWidth() &#x83B7;&#x53D6;&#x7684;&#x662F;view&#x539F;&#x59CB;&#x7684;&#x5927;&#x5C0F;&#xFF0C;&#x4E5F;&#x5C31;&#x662F;&#x8FD9;&#x4E2A;view&#x5728;XML&#x6587;&#x4EF6;&#x4E2D;&#x914D;&#x7F6E;&#x6216;&#x8005;&#x662F;&#x4EE3;&#x7801;&#x4E2D;&#x8BBE;&#x7F6E;&#x7684;&#x5927;&#x5C0F;&#x3002;
getWidth() &#x83B7;&#x53D6;&#x7684;&#x662F;&#x8FD9;&#x4E2A;view&#x6700;&#x7EC8;&#x663E;&#x793A;&#x7684;&#x5927;&#x5C0F;&#xFF0C;&#x4ED6;&#x4EEC;&#x4E0D;&#x4E00;&#x5B9A;&#x76F8;&#x7B49;&#x3002;

1&#x3001;getMeasuredWidth() &#x7684;&#x8D4B;&#x503C;&#x5728;View&#x7684; setMeasuredDimension() &#x4E2D;&#xFF0C;
&#x5B83;&#x7684;&#x503C;&#x5728; onMeasure &#x65B9;&#x6CD5;&#x8FD0;&#x884C;&#x540E;&#x5C31;&#x4F1A;&#x786E;&#x5B9A;&#x3002;
&#x5728; setMeasuredDimension()&#x65B9;&#x6CD5;&#x8C03;&#x7528;&#x4E4B;&#x540E;&#xFF0C;&#x6211;&#x4EEC;&#x624D;&#x80FD;&#x4F7F;&#x7528; getMeasuredWidth() &#x548C; getMeasuredHeight() 
&#x6765;&#x83B7;&#x53D6;&#x89C6;&#x56FE;&#x6D4B;&#x91CF;&#x51FA;&#x7684;&#x5BBD;&#x9AD8;&#xFF0C;&#x4EE5;&#x6B64;&#x4E4B;&#x524D;&#x8C03;&#x7528;&#x8FD9;&#x4E24;&#x4E2A;&#x65B9;&#x6CD5;&#x5F97;&#x5230;&#x7684;&#x503C;&#x90FD;&#x4F1A;&#x662F;0&#x3002;

2&#x3001;getWidth() &#x5728; onLayout() &#x5B8C;&#x6210;&#x540E;&#x624D;&#x4F1A;&#x88AB;&#x8D4B;&#x503C;&#x3002;
</code></pre>
<h2 id="window-&#x5C3A;&#x5BF8;&#x6D4B;&#x91CF;&#x6D41;&#x7A0B;"><a name="window-&#x5C3A;&#x5BF8;&#x6D4B;&#x91CF;&#x6D41;&#x7A0B;" class="anchor-navigation-ex-anchor" href="#window-&#x5C3A;&#x5BF8;&#x6D4B;&#x91CF;&#x6D41;&#x7A0B;"><i class="fa fa-link" aria-hidden="true"></i></a>2.6. Window &#x5C3A;&#x5BF8;&#x6D4B;&#x91CF;&#x6D41;&#x7A0B;</h2>
<p>&#x57FA;&#x4E8E;7.1.1&#x6E90;&#x7801;</p>
<pre><code class="lang-text">WindowManager.addView() , WindowManager&#x7684;&#x5B9E;&#x73B0;&#x7C7B;&#x662F; WindowManagerImpl &#xFF0C;
&#x6240;&#x4EE5;&#x76F4;&#x63A5;&#x770B; WindowManagerImpl&#x7684; addView() 
public void addView( View view, ViewGroup.LayoutParams params) {
    applyDefaultToken(params);
    // WindowManagerGlobal  mGlobal
    mGlobal.addView(view, params, mContext.getDisplay(), mParentWindow);
}

&#x8DF3;&#x8F6C;&#x5230; WindowManagerGlobal.addView()
public void addView(View view, ViewGroup.LayoutParams params ...) {
    final WindowManager.LayoutParams wparams = (WindowManager.LayoutParams) params;
    ViewRootImpl root;
    View panelParentView = null;
    synchronized (mLock) {
        // &#x4F20;&#x8FDB;&#x6765;&#x7684; View &#x4F5C;&#x4E3A; &#x6839;&#x5E03;&#x5C40;
        root = new ViewRootImpl(view.getContext(), display);
        view.setLayoutParams(wparams); // &#x4F20;&#x8FDB;&#x7684; LayoutParams &#x4F5C;&#x4E3A; root &#x7684;&#x53C2;&#x6570;
        mViews.add(view);  // &#x8BB0;&#x5F55;&#x4FDD;&#x5B58; view
        mRoots.add(root);
        mParams.add(wparams);
    }
    // ViewRootImpl &#x548C; View &#x5173;&#x8054;&#x8D77;&#x6765;
    root.setView(view, wparams, panelParentView);
}

// &#x8DF3;&#x8F6C;&#x5230; ViewRootImpl &#x7684; setView()
public void setView(View view, WindowManager.LayoutParams attrs, View panelParentView) {
    synchronized (this) {
        if (mView == null) {
            mView = view;
            mWindowAttributes.copyFrom(attrs); // &#x5C06; LayoutParams &#x4FDD;&#x5B58;&#x8D77;&#x6765; 
            attrs = mWindowAttributes;
            requestLayout();// &#x5F00;&#x542F; view &#x7684;&#x4E09;&#x5927;&#x6D41;&#x7A0B;
            try {
                // IPC &#x8DE8;&#x8FDB;&#x7A0B;&#x901A;&#x4FE1; &#xFF0C;&#x901A;&#x77E5; WindowManagerService &#x53BB;&#x521B;&#x5EFA; Window
                // &#x5C06; LayoutParams &#x4F5C;&#x4E3A;&#x53C2;&#x6570;&#x4F20;&#x9012;&#x8FC7;&#x53BB;
                // &#x8FD4;&#x56DE;&#x7684; res &#x8868;&#x793A;&#x8FD9;&#x4E2A; Window &#x53EF;&#x4EE5;&#x5C55;&#x793A;&#x7684;&#x6700;&#x5927;&#x5C3A;&#x5BF8; 
                res = mWindowSession.addToDisplay(mWindow, mSeq, mWindowAttributes,
                        getHostVisibility(), mDisplay.getDisplayId(),
                        mAttachInfo.mContentInsets, mAttachInfo.mStableInsets,
                        mAttachInfo.mOutsets, mInputChannel);
            } catch (RemoteException e) {
                throw new RuntimeException(&quot;Adding window failed&quot;, e);
            } 
            // &#x4F7F;&#x7528;&#x548C;&#x4FDD;&#x5B58; res
            mAddedTouchMode = (res &amp; WindowManagerGlobal.ADD_FLAG_IN_TOUCH_MODE) != 0;
            mAppVisible = (res &amp; WindowManagerGlobal.ADD_FLAG_APP_VISIBLE) != 0;
        }
    }
}
&#x4ECE;&#x4E0A;&#x8FF0;&#x4EE3;&#x7801;&#x53EF;&#x4EE5;&#x770B;&#x51FA; LayoutParams &#x4F5C;&#x7528;&#x4E8E; &#x81EA;&#x5B9A;&#x4E49;&#x7684;View &#x548C; Window
</code></pre>
<h2 id="&#x6BCF;&#x6B21;-performmeasure-&#x4E00;&#x5B9A;&#x80FD;&#x591F;&#x89E6;&#x53D1;&#x6267;&#x884C;onmeasure&#x5417;&#xFF1F;&#x4F1A;&#x3002;"><a name="&#x6BCF;&#x6B21;-performmeasure-&#x4E00;&#x5B9A;&#x80FD;&#x591F;&#x89E6;&#x53D1;&#x6267;&#x884C;onmeasure&#x5417;&#xFF1F;&#x4F1A;&#x3002;" class="anchor-navigation-ex-anchor" href="#&#x6BCF;&#x6B21;-performmeasure-&#x4E00;&#x5B9A;&#x80FD;&#x591F;&#x89E6;&#x53D1;&#x6267;&#x884C;onmeasure&#x5417;&#xFF1F;&#x4F1A;&#x3002;"><i class="fa fa-link" aria-hidden="true"></i></a>2.7. &#x6BCF;&#x6B21; performMeasure() &#x4E00;&#x5B9A;&#x80FD;&#x591F;&#x89E6;&#x53D1;&#x6267;&#x884C;onMeasure()&#x5417;&#xFF1F;&#x4F1A;&#x3002;</h2>
<pre><code class="lang-text">// ViewRootImpl.java
private void performMeasure(int childWidthMeasureSpec, int childHeightMeasureSpec) {
    mView.measure(childWidthMeasureSpec, childHeightMeasureSpec);
}

//  View.java 
public final void measure(int widthMeasureSpec, int heightMeasureSpec) {
    final boolean forceLayout = (mPrivateFlags &amp; PFLAG_FORCE_LAYOUT) == PFLAG_FORCE_LAYOUT;
    final boolean needsLayout = specChanged &amp;&amp; (sAlwaysRemeasureExactly || !isSpecExactly || !matchesSpecSize);
     // &#x9700;&#x8981;&#x5F3A;&#x5236;layout &#x3001;&#x5C3A;&#x5BF8;&#x53D1;&#x751F;&#x53D8;&#x5316;layout 
    if (forceLayout || needsLayout) {
        onMeasure(widthMeasureSpec, heightMeasureSpec);
    }
    &#x56E0;&#x4E3A;View&#x5C3A;&#x5BF8;&#x6CA1;&#x53D8;&#x8FC7;&#xFF0C;&#x6240;&#x4EE5; needsLayout &#x662F;&#x4E0D;&#x6EE1;&#x8DB3;&#x7684;&#xFF0C;
    &#x90A3;&#x4E48;&#x53EA;&#x80FD;&#x662F; forceLayout=true&#x4E86;&#x3002;
    &#x5728;&#x7B2C;&#x4E00;&#x6B21;&#x6D4B;&#x91CF; ViewTree &#x7684;&#x65F6;&#x5019;&#xFF0C;&#x4EC5;&#x4EC5;&#x53EA;&#x662F;&#x8D70;&#x4E86; Measure &#x8FC7;&#x7A0B;&#xFF0C;&#x5E76;&#x672A;&#x8D70;Layout&#x8FC7;&#x7A0B;&#x3002;
    &#x800C;&#x6211;&#x4EEC;&#x77E5;&#x9053; PFLAG_FORCE_LAYOUT &#x6807;&#x8BB0;&#x662F;&#x5728; Layout &#x7ED3;&#x675F;&#x540E;&#x6E05;&#x7A7A;&#x7684;&#xFF0C;&#x56E0;&#x6B64;&#x6B64;&#x5904; PFLAG_FORCE_LAYOUT &#x6807;&#x8BB0;&#x5E76;&#x6CA1;&#x6709;&#x6E05;&#x7A7A;&#xFF0C;
    &#x5F53;&#x7136; needsLayout=true &#x6EE1;&#x8DB3;&#x6761;&#x4EF6;&#x3002;&#x6240;&#x4EE5; if (forceLayout || needsLayout) &#x4F1A;&#x6267;&#x884C;&#x3002;
}
</code></pre>
<h2 id="&#x4E3A;&#x4EC0;&#x4E48;&#x4F1A;&#x591A;&#x6B21;&#x8C03;&#x7528;-onmeasure-&#x81F3;&#x5C11;2&#x6B21;"><a name="&#x4E3A;&#x4EC0;&#x4E48;&#x4F1A;&#x591A;&#x6B21;&#x8C03;&#x7528;-onmeasure-&#x81F3;&#x5C11;2&#x6B21;" class="anchor-navigation-ex-anchor" href="#&#x4E3A;&#x4EC0;&#x4E48;&#x4F1A;&#x591A;&#x6B21;&#x8C03;&#x7528;-onmeasure-&#x81F3;&#x5C11;2&#x6B21;"><i class="fa fa-link" aria-hidden="true"></i></a>2.8. &#x4E3A;&#x4EC0;&#x4E48;&#x4F1A;&#x591A;&#x6B21;&#x8C03;&#x7528; onMeasure() ,&#x81F3;&#x5C11;2&#x6B21;</h2>
<p>&#x57FA;&#x4E8E;7.1.1&#x6E90;&#x7801;</p>
<pre><code class="lang-text">ViewRootImpl &#x5728; setView() &#x4E2D;&#x8C03;&#x7528;&#x4E86;requestLayout &#x6CE8;&#x518C;&#x4E86;&#x56DE;&#x8C03;&#xFF0C;
&#x5F53;&#x5C4F;&#x5E55;&#x5237;&#x65B0;&#x4FE1;&#x53F7;&#x5230;&#x6765;&#x4E4B;&#x65F6;&#x6267;&#x884C; performTraversals() &#x5F00;&#x542F;&#x4E09;&#x5927;&#x6D41;&#x7A0B;&#x3002;
public void setView( ) {
   requestLayout();// &#x7ECF;&#x8FC7;&#x51E0;&#x4E2A;&#x65B9;&#x6CD5;&#x7684;&#x8DF3;&#x8F6C; &#x6700;&#x540E;&#x4F1A;&#x8C03;&#x7528; scheduleTraversals()
}

// WindowManagerImpl.java 
// &#x5728; performTraversals() &#x6709;5&#x4E2A;&#x91CD;&#x8981;&#x6B65;&#x9AA4;
private void performTraversals() {
    WindowManager.LayoutParams lp = mWindowAttributes;// addView() &#x4FDD;&#x5B58;&#x7684;&#x5E03;&#x5C40;&#x53C2;&#x6570;
    int desiredWindowWidth; // Window &#x9700;&#x8981;&#x7684;&#x957F;&#x5BBD;
    int desiredWindowHeight;
    Rect frame = mWinFrame;
    if (mFirst) {
        if (shouldUseDisplaySize(lp)) {
        } else {
            // &#x83B7;&#x53D6;&#x5728; setView() &#x4FDD;&#x5B58;&#x7684; WindowManagerService &#x8FD4;&#x56DE;&#x7684; Window&#x957F;&#x5BBD;
            desiredWindowWidth = dipToPx(config.screenWidthDp);
            desiredWindowHeight = dipToPx(config.screenHeightDp);
        }
    if (layoutRequested) {
        final Resources res = mView.getContext().getResources();
        // Ask host how big it wants to be &#xFF0C;&#x6D4B;&#x91CF; ViewTree  &#x2460;
        windowSizeMayChange |= measureHierarchy(host, lp, res,desiredWindowWidth, desiredWindowHeight);
    }
    if (mFirst || mAttachInfo.mViewVisibilityChanged) {
        // &#x91CD;&#x65B0;&#x786E;&#x5B9A; Window &#x7684;&#x5C3A;&#x5BF8;  &#x2461;
        relayoutResult = relayoutWindow(params, viewVisibility, insetsPending);
         ...
        if (!mStopped || mReportNextDraw) {
            if (focusChangedDueToTouchMode || mWidth != host.getMeasuredWidth()
                    || mHeight != host.getMeasuredHeight() || contentInsetsChanged ||
                    updatedConfiguration) {
                 // &#x518D;&#x6B21;&#x6D4B;&#x91CF; ViewTree &#x2462;
                performMeasure(childWidthMeasureSpec, childHeightMeasureSpec);
         ...     
    if (didLayout) {
       // &#x5BF9; ViewTree &#x8FDB;&#x884C; Layout  &#x2463;
        performLayout(lp, mWidth, mHeight);
     ...  
    if (!cancelDraw &amp;&amp; !newSurface) {
        //  &#x5F00;&#x59CB; &#x5BF9; ViewTree &#x8FDB;&#x884C;&#x7ED8;&#x5236;  &#x2464;
        performDraw();
    }  
}    

&#x6B65;&#x9AA4;&#x2460; measureHierarchy()
&#x8FD9;&#x4E2A;&#x51FD;&#x6570;&#x4F5C;&#x7528;&#x662F; 
1&#x3001;&#x7ED3;&#x5408; Window&#x5C3A;&#x5BF8;&#xFF0C;&#x786E;&#x5B9A; RootView &#x7684;&#x6D4B;&#x91CF;&#x6A21;&#x5F0F;&#x548C;&#x9884;&#x4F30;&#x6D4B;&#x91CF;&#x503C; (MeasureSpec)
2&#x3001;&#x6839;&#x636E; MeasureSpec &#xFF0C;&#x53D1;&#x8D77;&#x5BF9; ViewTree&#x7684;&#x6D4B;&#x91CF;&#xFF08;&#x4ECE;RootView&#x5F00;&#x59CB;)
measureHierarchy() &#x6267;&#x884C;&#x540E;&#xFF0C;RootView &#x7684;&#x6D4B;&#x91CF;&#x503C;&#x5DF2;&#x7ECF;&#x786E;&#x5B9A;&#x4E86;&#x3002;
measureHierarchy() &#x6D4B;&#x91CF; ViewTree &#x662F;&#x4E3A;&#x4E86;&#x786E;&#x5B9A; RootView &#x7684;&#x5C3A;&#x5BF8;,

&#x6B65;&#x9AA4;&#x2461; relayoutWindow()  
relayoutWindow() &#x4F9D;&#x8D56;&#x4E8E; RootView &#x7684;&#x6D4B;&#x91CF;&#x5C3A;&#x5BF8; &#x8FDB;&#x800C;&#x786E;&#x5B9A; Window &#x5C3A;&#x5BF8;&#x3002;

&#x8DDF;&#x7740;&#x535A;&#x5BA2;&#x8FD8;&#x6CA1;&#x770B;&#x5B8C;&#xFF0C;&#x7D2F;&#x4E86;&#xFF0C;&#x4E0B;&#x6B21;&#x7EE7;&#x7EED;&#x770B; 
https://www.jianshu.com/p/6e45f42da304
</code></pre>
<h2 id="&#x4E3A;&#x4EC0;&#x4E48;&#x4F1A;&#x591A;&#x6B21;&#x8C03;&#x7528;--onlayout"><a name="&#x4E3A;&#x4EC0;&#x4E48;&#x4F1A;&#x591A;&#x6B21;&#x8C03;&#x7528;--onlayout" class="anchor-navigation-ex-anchor" href="#&#x4E3A;&#x4EC0;&#x4E48;&#x4F1A;&#x591A;&#x6B21;&#x8C03;&#x7528;--onlayout"><i class="fa fa-link" aria-hidden="true"></i></a>2.9. &#x4E3A;&#x4EC0;&#x4E48;&#x4F1A;&#x591A;&#x6B21;&#x8C03;&#x7528;  onLayout()</h2>
<pre><code class="lang-text">

</code></pre>
<h1 id="&#x81EA;&#x5B9A;&#x4E49;&#x63A7;&#x4EF6;"><a name="&#x81EA;&#x5B9A;&#x4E49;&#x63A7;&#x4EF6;" class="anchor-navigation-ex-anchor" href="#&#x81EA;&#x5B9A;&#x4E49;&#x63A7;&#x4EF6;"><i class="fa fa-link" aria-hidden="true"></i></a>3. &#x81EA;&#x5B9A;&#x4E49;&#x63A7;&#x4EF6;</h1>
<h2 id="&#x81EA;&#x5B9A;&#x4E49;view&#x7684;&#x610F;&#x4E49;"><a name="&#x81EA;&#x5B9A;&#x4E49;view&#x7684;&#x610F;&#x4E49;" class="anchor-navigation-ex-anchor" href="#&#x81EA;&#x5B9A;&#x4E49;view&#x7684;&#x610F;&#x4E49;"><i class="fa fa-link" aria-hidden="true"></i></a>3.1. &#x81EA;&#x5B9A;&#x4E49;View&#x7684;&#x610F;&#x4E49;</h2>
<pre><code class="lang-text">1&#x3001;&#x5B9E;&#x73B0;&#x57FA;&#x7840;&#x63A7;&#x4EF6;&#x65E0;&#x6CD5;&#x505A;&#x5230;&#x7684;&#x7279;&#x6548;&#x3002;
2&#x3001;&#x4EE3;&#x7801;&#x5C01;&#x88C5;&#x540E;&#x65B9;&#x4FBF;&#x7ED9;&#x5176;&#x4ED6;&#x6210;&#x5458;&#x5171;&#x7528;&#xFF0C;&#x65E0;&#x9700;&#x91CD;&#x590D;&#x9020;&#x8F6E;&#x5B50;&#x3002;
3&#x3001;&#x5C06;&#x63A7;&#x4EF6;&#x7684;&#x5185;&#x90E8;&#x903B;&#x8F91;&#x5C01;&#x88C5;&#x5728;&#x81EA;&#x5B9A;&#x4E49;View&#x4E2D;&#xFF0C;&#x4FBF;&#x4E8E;&#x5E94;&#x7528;&#x5185;&#x89E3;&#x8026;
</code></pre>
<h2 id="android&#x81EA;&#x5B9A;&#x4E49;view&#x7C7B;&#x578B;"><a name="android&#x81EA;&#x5B9A;&#x4E49;view&#x7C7B;&#x578B;" class="anchor-navigation-ex-anchor" href="#android&#x81EA;&#x5B9A;&#x4E49;view&#x7C7B;&#x578B;"><i class="fa fa-link" aria-hidden="true"></i></a>3.2. Android&#x81EA;&#x5B9A;&#x4E49;View&#x7C7B;&#x578B;</h2>
<h3 id="1&#x3001;&#x7EC4;&#x5408;&#x63A7;&#x4EF6;"><a name="1&#x3001;&#x7EC4;&#x5408;&#x63A7;&#x4EF6;" class="anchor-navigation-ex-anchor" href="#1&#x3001;&#x7EC4;&#x5408;&#x63A7;&#x4EF6;"><i class="fa fa-link" aria-hidden="true"></i></a>3.2.1. 1&#x3001;&#x7EC4;&#x5408;&#x63A7;&#x4EF6;</h3>
<p>&#x5C06;&#x57FA;&#x7840;&#x63A7;&#x4EF6;(TextView&#x3001;ProgressBar&#x7B49;)&#x7EC4;&#x5408;&#x800C;&#x6210;&#xFF0C;&#x6BD4;&#x5982;&#x4E0B;&#x62C9;&#x5237;&#x65B0;&#x63A7;&#x4EF6;&#x7B49;&#x3002; </p>
<h3 id="2&#x3001;&#x5B8C;&#x5168;&#x81EA;&#x5B9A;&#x4E49;&#x63A7;&#x4EF6;"><a name="2&#x3001;&#x5B8C;&#x5168;&#x81EA;&#x5B9A;&#x4E49;&#x63A7;&#x4EF6;" class="anchor-navigation-ex-anchor" href="#2&#x3001;&#x5B8C;&#x5168;&#x81EA;&#x5B9A;&#x4E49;&#x63A7;&#x4EF6;"><i class="fa fa-link" aria-hidden="true"></i></a>3.2.2. 2&#x3001;&#x5B8C;&#x5168;&#x81EA;&#x5B9A;&#x4E49;&#x63A7;&#x4EF6;</h3>
<pre><code class="lang-text">&#x7EE7;&#x627F; View(UI&#x5728;&#x4E3B;&#x7EBF;&#x7A0B;&#x4E2D;&#x7ED8;&#x5236;)&#x3001;ViewGroup &#x7B49;&#x9876;&#x7EA7;&#x63A7;&#x4EF6;&#x6216; SurfaceView &#x7279;&#x5B9A;&#x63A7;&#x4EF6;&#x3002;
&#x96BE;&#x70B9;&#x5728;&#x4E8E;&#x7A0B;&#x5E8F;&#x7684;&#x8BBE;&#x8BA1;&#x3001;&#x4E8B;&#x4EF6;&#x4F20;&#x9012;&#x5904;&#x7406;&#x3001;&#x6548;&#x7387;&#x4F18;&#x5316;&#x3002;

SurfaceView extends View &#xFF0C;&#x4F46;&#x662F;&#x662F;&#x4E00;&#x4E2A;&#x6BD4;&#x8F83;&#x7279;&#x6B8A;&#x7684;&#x7CFB;&#x7EDF;&#x63A7;&#x4EF6;&#x3002;UI&#x5728;&#x4E00;&#x4E2A;&#x5B50;&#x7EBF;&#x7A0B;&#x4E2D;&#x8FDB;&#x884C;&#x7ED8;&#x5236;&#x3002;
</code></pre>
<h2 id="view&#x81EA;&#x5B9A;&#x4E49;&#x5C5E;&#x6027;"><a name="view&#x81EA;&#x5B9A;&#x4E49;&#x5C5E;&#x6027;" class="anchor-navigation-ex-anchor" href="#view&#x81EA;&#x5B9A;&#x4E49;&#x5C5E;&#x6027;"><i class="fa fa-link" aria-hidden="true"></i></a>3.3. View&#x81EA;&#x5B9A;&#x4E49;&#x5C5E;&#x6027;</h2>
<pre><code class="lang-text">&#x901A;&#x8FC7;&#x5B9A;&#x4E49;&#x5C5E;&#x6027;&#xFF0C;&#x4F7F;&#x5F97;&#x5F00;&#x53D1;&#x8005;&#x53EF;&#x4EE5;&#x5728;xml&#x4E2D;&#x5BF9;&#x63A7;&#x4EF6;&#x8FDB;&#x884C;&#x4E00;&#x4E9B;&#x53C2;&#x6570;&#x914D;&#x7F6E;&#x3002;
&#x4E0D;&#x8FC7;&#xFF0C;&#x6211;&#x4E0D;&#x559C;&#x6B22;&#x8FD9;&#x79CD;&#x65B9;&#x5F0F;&#xFF0C;&#x6211;&#x4E60;&#x60EF;&#x5728;&#x4EE3;&#x7801;&#x4E2D;&#x914D;&#x7F6E;&#x3002;
</code></pre>
<h2 id="&#x52A8;&#x6001;&#x4FEE;&#x6539;&#x9AD8;&#x5EA6;"><a name="&#x52A8;&#x6001;&#x4FEE;&#x6539;&#x9AD8;&#x5EA6;" class="anchor-navigation-ex-anchor" href="#&#x52A8;&#x6001;&#x4FEE;&#x6539;&#x9AD8;&#x5EA6;"><i class="fa fa-link" aria-hidden="true"></i></a>3.4. &#x52A8;&#x6001;&#x4FEE;&#x6539;&#x9AD8;&#x5EA6;</h2>
<pre><code class="lang-text">private void setViewHeight(View view, int height) {
    // &#x7236;&#x5BB9;&#x5668;&#x4E3A;&#x7EA6;&#x675F;&#x5E03;&#x5C40;&#x65F6;&#xFF0C;&#x6B64;&#x5904;&#x6709;&#x4E00;&#x4E2A;bug&#xFF0C;
    // &#x52A8;&#x6001;&#x8BBE;&#x7F6E;&#xFF0C;&#x9AD8;&#x5EA6;&#x4E3A; 0&#x65F6;&#xFF0C;&#x8BBE;&#x7F6E;setLayoutParams &#x4F1A;&#x5F02;&#x5E38;&#xFF0C;view.getHeight() &#x4F1A;&#x53D8;&#x6210;&#x539F;&#x59CB;&#x9AD8;&#x5EA6;&#x3002;
    // &#x539F;&#x56E0;&#x6682;&#x65F6;&#x672A;&#x77E5;&#x3002;
    if(height&lt;=0){
        height = 1 ;
    }
    ViewGroup.LayoutParams params = view.getLayoutParams();
    params.height = height;
    view.requestLayout();
    view.setLayoutParams(params);
}
</code></pre>
<h1 id="&#x6587;&#x5B57;&#x7ED8;&#x5236;"><a name="&#x6587;&#x5B57;&#x7ED8;&#x5236;" class="anchor-navigation-ex-anchor" href="#&#x6587;&#x5B57;&#x7ED8;&#x5236;"><i class="fa fa-link" aria-hidden="true"></i></a>4. &#x6587;&#x5B57;&#x7ED8;&#x5236;</h1>
<h2 id="&#x6587;&#x5B57;&#x5BBD;&#x5EA6;"><a name="&#x6587;&#x5B57;&#x5BBD;&#x5EA6;" class="anchor-navigation-ex-anchor" href="#&#x6587;&#x5B57;&#x5BBD;&#x5EA6;"><i class="fa fa-link" aria-hidden="true"></i></a>4.1. &#x6587;&#x5B57;&#x5BBD;&#x5EA6;</h2>
<pre><code class="lang-text">// measureText &#x6D4B;&#x91CF;&#x6587;&#x5B57;&#x7ED8;&#x5236;&#x65F6;&#x6240;&#x5360;&#x7528;&#x7684;&#x5BBD;&#x5EA6;&#x3002;
// &#x4E00;&#x4E2A;&#x6587;&#x5B57;&#x5728;&#x754C;&#x9762;&#x4E2D;&#xFF0C;&#x5F80;&#x5F80;&#x9700;&#x8981;&#x5360;&#x7528;&#x6BD4;&#x4ED6;&#x7684;&#x5B9E;&#x9645;&#x663E;&#x793A;&#x5BBD;&#x5EA6;&#x66F4;&#x591A;&#x4E00;&#x70B9;&#x7684;&#x5BBD;&#x5EA6;&#xFF0C;
// &#x4EE5;&#x6B64;&#x6765;&#x8BA9;&#x6587;&#x5B57;&#x548C;&#x6587;&#x5B57;&#x4E4B;&#x95F4;&#x4FDD;&#x7559;&#x4E00;&#x4E9B;&#x95F4;&#x8DDD;&#xFF0C;&#x4E0D;&#x4F1A;&#x663E;&#x5F97;&#x8FC7;&#x4E8E;&#x62E5;&#x6324;&#x3002;
float textWidth= mPaint.measureText(distanceInfo) ;

// getTextBounds &#x6D4B;&#x91CF;&#x7684;&#x662F;&#x6587;&#x5B57;&#x7684;&#x663E;&#x793A;&#x8303;&#x56F4;,
// &#x8FD9;&#x6BB5;&#x6587;&#x5B57;&#x5916;&#x653E;&#x7F6E;&#x4E00;&#x4E2A;&#x53EF;&#x53D8;&#x7684;&#x77E9;&#x5F62;&#xFF0C;&#x7136;&#x540E;&#x628A;&#x77E9;&#x5F62;&#x5C3D;&#x53EF;&#x80FD;&#x5730;&#x7F29;&#x5C0F;&#xFF0C;
// &#x4E00;&#x76F4;&#x5C0F;&#x5230;&#x8FD9;&#x4E2A;&#x77E9;&#x5F62;&#x6070;&#x597D;&#x7D27;&#x7D27;&#x5305;&#x88F9;&#x4F4F;&#x6587;&#x5B57;&#xFF0C;&#x90A3;&#x4E48;&#x8FD9;&#x4E2A;&#x77E9;&#x5F62;&#x7684;&#x8303;&#x56F4;&#xFF0C;&#x5C31;&#x662F;&#x8FD9;&#x6BB5;&#x6587;&#x5B57;&#x7684; bounds&#x3002;
mPaint.getTextBounds(distanceInfo, 0, distanceInfo.length(), rect);
WkLog.showLog(&quot;textWidth2=&quot;+rect.width()+&quot;  &quot;+ rect.height());

// getTextWidths &#x83B7;&#x53D6;&#x5B57;&#x7B26;&#x4E32;&#x4E2D;&#x6BCF;&#x4E2A;&#x5B57;&#x7B26;&#x7684;&#x5BBD;&#x5EA6;&#xFF0C;&#x5E76;&#x628A;&#x7ED3;&#x679C;&#x586B;&#x5165; &#x53C2;&#x6570; widths
float[] widths =new float[distanceInfo.length()] ;
mPaint.getTextWidths(distanceInfo ,widths) ;
float sumWidth =0 ;
for(float value : widths){
    sumWidth+=value ;
}
</code></pre>
<h2 id="&#x6587;&#x5B57;&#x9AD8;&#x5EA6;"><a name="&#x6587;&#x5B57;&#x9AD8;&#x5EA6;" class="anchor-navigation-ex-anchor" href="#&#x6587;&#x5B57;&#x9AD8;&#x5EA6;"><i class="fa fa-link" aria-hidden="true"></i></a>4.2. &#x6587;&#x5B57;&#x9AD8;&#x5EA6;</h2>
<pre><code class="lang-text">&#x4EE5;&#x4E0B;&#x9AD8;&#x5EA6;&#x662F;&#x6709;&#x5DEE;&#x5F02;&#x7684;&#xFF0C;&#x8BF7;&#x7406;&#x89E3;&#x5B9A;&#x4E49;&#x6807;&#x51C6;&#x3002;

// &#x901A;&#x8FC7; FontMetrics &#x83B7;&#x53D6;
Paint.FontMetrics fm=mPaint.getFontMetrics();
float textHeight1=fm.bottom-fm.top; 
// &#x901A;&#x8FC7; Paint &#x83B7;&#x53D6;
float textHeight2=mPaint.descent()-mPaint.ascent();
// &#x901A;&#x8FC7; getTextBounds &#x83B7;&#x53D6;
mPaint.getTextBounds(stringInfo, 0,stringInfo.length(), bounds);  

&#x5BF9;&#x4E8E;&#x5927;&#x90E8;&#x5206;&#x4E2D;&#x6587;&#x82F1;&#x6587;&#xFF0C;&#x9AD8;&#x5EA6;&#x5982;&#x679C;&#x7528; top &#x548C; bottom &#x8BA1;&#x7B97;&#xFF0C;&#x4F1A;&#x6709;&#x504F;&#x5DEE;&#xFF0C;&#x5B57;
&#x4F53;&#x88AB;&#x504F;&#x4E0B;&#x4E86;&#x4E00;&#x70B9;&#x70B9;&#xFF0C;&#x5E94;&#x8BE5;&#x7528;ascent&#x548C;descent&#x8BA1;&#x7B97;
&#x90E8;&#x5206;&#x56FD;&#x5BB6;&#x7684;&#x7279;&#x6B8A;&#x5B57;&#x7B26;&#x7684;&#x4E0A;&#x4E0B;&#x9AD8;&#x5EA6;&#x4F1A;&#x8D85;&#x8FC7;descent&#xFF0C;ascent&#xFF0C;&#x7528;top&#x548C;bottom&#x8BA1;&#x7B97; &#x3002;
</code></pre>
<h2 id="&#x5B57;&#x7B26;&#x95F4;&#x8DDD;"><a name="&#x5B57;&#x7B26;&#x95F4;&#x8DDD;" class="anchor-navigation-ex-anchor" href="#&#x5B57;&#x7B26;&#x95F4;&#x8DDD;"><i class="fa fa-link" aria-hidden="true"></i></a>4.3. &#x5B57;&#x7B26;&#x95F4;&#x8DDD;</h2>
<pre><code class="lang-text">// &#x5B57;&#x7B26;&#x884C;&#x95F4;&#x8DDD; &#xFF0C;&#x8FD9;&#x4E2A;&#x503C;&#x662F;&#x7CFB;&#x7EDF;&#x6839;&#x636E;&#x6587;&#x5B57;&#x7684;&#x5B57;&#x4F53;&#x548C;&#x5B57;&#x53F7;&#x81EA;&#x52A8;&#x8BA1;&#x7B97;&#x7684;&#x3002;(&#x65E0;&#x6CD5;&#x76F4;&#x63A5;&#x8BBE;&#x7F6E;)
float space= mPaint.getFontSpacing();
// &#x5B57;&#x7B26;&#x4E4B;&#x95F4;&#x7684;&#x95F4;&#x8DDD;
float letterSpace =mPaint.getLetterSpacing();
WkLog.showLog(&quot;letterSpace=&quot;+letterSpace);
mPaint.setLetterSpacing(2.1f) ;
</code></pre>
<h2 id="drawtext-&#x57FA;&#x51C6;&#x70B9;"><a name="drawtext-&#x57FA;&#x51C6;&#x70B9;" class="anchor-navigation-ex-anchor" href="#drawtext-&#x57FA;&#x51C6;&#x70B9;"><i class="fa fa-link" aria-hidden="true"></i></a>4.4. drawText() &#x57FA;&#x51C6;&#x70B9;</h2>
<pre><code class="lang-text">canvas.drawText(stringInfo, x, y, mPaint);
</code></pre>
<p><img src="../pics/&#x6587;&#x5B57;&#x57FA;&#x51C6;&#x70B9;.png" alt=""></p>
<h2 id="fontmetrics"><a name="fontmetrics" class="anchor-navigation-ex-anchor" href="#fontmetrics"><i class="fa fa-link" aria-hidden="true"></i></a>4.5. FontMetrics</h2>
<pre><code class="lang-text">Android&#x6587;&#x672C;&#x7ED8;&#x5236;&#x662F;&#x4EE5; baseline &#x4E3A; y  &#xFF0C;&#x4EE5;&#x57FA;&#x51C6;&#x70B9;&#x5F00;&#x59CB;&#x7ED8;&#x5236;&#x3002;
&#x89C4;&#x5B9A; baseline &#x7684;y &#x5750;&#x6807;&#x4E3A;0 &#xFF0C;
&#x6240;&#x4EE5; top &#x548C; ascent &#x503C;&#x662F;&#x8D1F;&#x503C;&#xFF0C; descent &#x548C; bottom &#x7684;&#x503C;&#x662F;&#x6B63;&#x503C;&#x3002;
&#x8981;&#x5728;&#x8BBE;&#x7F6E;&#x5B8C;Paint&#x7684;&#x6587;&#x5B57;&#x5927;&#x5C0F;&#xFF0C;&#x5BBD;&#x5EA6;&#x4E4B;&#x7C7B;&#x5C5E;&#x6027;&#x540E;&#x518D;&#x83B7;&#x53D6; FontMetrics &#x3002;

fontMetrics.leading  // &#x4E0A;&#x4E00;&#x884C;&#x6587;&#x5B57;&#x7684;descent&#x5230;&#x5F53;&#x524D;&#x884C;&#x6587;&#x5B57;&#x7684;ascent &#xFF0C;&#x5373;&#x884C;&#x95F4;&#x8DDD;&#x3002;
fontMetrics.ascent   // &#x5230;&#x5B57;&#x7B26;&#x6700;&#x9AD8;&#x5904;&#x8DDD;&#x79BB; 
fontMetrics.descent  // &#x5230;&#x5B57;&#x7B26;&#x6700;&#x4F4E;&#x5904;&#x8DDD;&#x79BB; 
fontMetrics.top      // ascent &#x4E0A;&#x9762; &#x6709;&#x4E00;&#x6BB5;&#x9884;&#x7559;&#x7684;&#x7A7A;&#x95F4;&#xFF0C;&#x7528;&#x4E8E;&#x663E;&#x793A;&#x8BFB;&#x97F3;&#x7B26;&#x53F7;&#x7B49;
fontMetrics.bottom   // descent &#x4E0B;&#x9762;&#x8FD8;&#x4F1A;&#x6709;&#x4E00;&#x6BB5;&#x9884;&#x7559;&#x7684;&#x7A7A;&#x95F4;&#xFF0C;&#x7528;&#x4E8E;&#x663E;&#x793A;&#x8BFB;&#x97F3;&#x7B26;&#x53F7;&#x7B49;
</code></pre>
<p><img src="../pics/FontMetrics.png" alt=""></p>
<h2 id="&#x77E9;&#x5F62;&#x4E2D;&#x6587;&#x5B57;&#x5C45;&#x4E2D;"><a name="&#x77E9;&#x5F62;&#x4E2D;&#x6587;&#x5B57;&#x5C45;&#x4E2D;" class="anchor-navigation-ex-anchor" href="#&#x77E9;&#x5F62;&#x4E2D;&#x6587;&#x5B57;&#x5C45;&#x4E2D;"><i class="fa fa-link" aria-hidden="true"></i></a>4.6. &#x77E9;&#x5F62;&#x4E2D;&#x6587;&#x5B57;&#x5C45;&#x4E2D;</h2>
<pre><code class="lang-text">canvas.drawRect(rectF ,mPaint);
// &#x7ED8;&#x5236;&#x6587;&#x5B57;
Paint.FontMetrics fontMetrics= mPaint.getFontMetrics();
float distance0=(fontMetrics.bottom - fontMetrics.top)/2 - fontMetrics.bottom;
float baseY=rectF.centerY() + distance0; // &#x57FA;&#x70B9;&#x5750;&#x6807;Y = &#x77E9;&#x5F62;Y&#x5750;&#x6807; + &#x77E9;&#x5F62;&#x4E2D;&#x5FC3;&#x4E0E;&#x57FA;&#x7EBF;&#x7684;&#x8DDD;&#x79BB;
float baseX = viewWith/2f ;
mPaint.setColor(Color.RED);
canvas.drawText(strInfo,baseX ,baseY ,mPaint);
</code></pre>
<h1 id="&#x5706;&#x89D2;&#x56FE;&#x7247;"><a name="&#x5706;&#x89D2;&#x56FE;&#x7247;" class="anchor-navigation-ex-anchor" href="#&#x5706;&#x89D2;&#x56FE;&#x7247;"><i class="fa fa-link" aria-hidden="true"></i></a>5. &#x5706;&#x89D2;&#x56FE;&#x7247;</h1>
<p><img src="../pics/&#x5706;&#x89D2;&#x56FE;&#x7247;.png" alt=""></p>
<h2 id="&#x901A;&#x8FC7;-paintsetxfermode-&#x7ED8;&#x5236;-&#x4F20;&#x7EDF;&#x65B9;&#x6CD5;"><a name="&#x901A;&#x8FC7;-paintsetxfermode-&#x7ED8;&#x5236;-&#x4F20;&#x7EDF;&#x65B9;&#x6CD5;" class="anchor-navigation-ex-anchor" href="#&#x901A;&#x8FC7;-paintsetxfermode-&#x7ED8;&#x5236;-&#x4F20;&#x7EDF;&#x65B9;&#x6CD5;"><i class="fa fa-link" aria-hidden="true"></i></a>5.1. &#x901A;&#x8FC7; paint.setXfermode &#x7ED8;&#x5236;( &#x4F20;&#x7EDF;&#x65B9;&#x6CD5;)</h2>
<pre><code class="lang-text">&#x5F53;&#x7ED8;&#x5236;&#x591A;&#x4E2A;&#x56FE;&#x5C42;&#x53E0;&#x52A0;&#x7684;&#x65F6;&#x5019;&#x3002;
&#x5728;&#x4E24;&#x4E2A;&#x7ED8;&#x5236;&#x56FE;&#x5F62;&#x8FC7;&#x7A0B;&#x4E2D;&#xFF0C;Pain &#x6DFB;&#x52A0;Xfermode&#x7ED8;&#x5236;&#x6A21;&#x5F0F;&#xFF0C;&#x80FD;&#x591F;&#x6539;&#x53D8;&#x4E24;&#x4E2A;&#x56FE;&#x7684;&#x53E0;&#x52A0;&#x6548;&#x679C;&#x3002;
XferMode&#x4E3B;&#x8981;&#x662F;&#x5C06;2&#x5F20;&#x56FE;&#x7247;&#x5408;&#x5728;&#x4E00;&#x8D77;&#xFF0C;&#x6839;&#x636E;&#x4E0D;&#x540C;&#x7684;&#x53C2;&#x6570;&#x5B9E;&#x73B0;&#x4E0D;&#x540C;&#x7684;&#x6548;&#x679C; &#x3002;
&#x7C7B;&#x4F3C;ps&#x4E2D;&#x7684; mask &#x906E;&#x7F69;&#x6548;&#x679C;&#x539F;&#x7406;&#x3002;
</code></pre>
<p><img src="../pics/XferModeType.png" alt=""></p>
<h3 id="mask-&#x5B9E;&#x73B0;&#x5706;&#x89D2;&#x6548;&#x679C;"><a name="mask-&#x5B9E;&#x73B0;&#x5706;&#x89D2;&#x6548;&#x679C;" class="anchor-navigation-ex-anchor" href="#mask-&#x5B9E;&#x73B0;&#x5706;&#x89D2;&#x6548;&#x679C;"><i class="fa fa-link" aria-hidden="true"></i></a>5.1.1. mask &#x5B9E;&#x73B0;&#x5706;&#x89D2;&#x6548;&#x679C;</h3>
<pre><code class="lang-text">// &#x5706;&#x89D2;&#x5904;&#x622A;&#x53D6;&#x591A;&#x4F59;&#x7684;&#x7EA2;&#x7EBF;
int layerId = canvas.saveLayer(0, 0, this.getWidth(), this.getHeight(), mPaint, Canvas.ALL_SAVE_FLAG);//&#x4FDD;&#x5B58;&#x56FE;&#x5C42;
mPaint.setColor(Color.WHITE); // &#x5047;&#x50CF;
canvas.drawRect(0,0 ,getWidth() ,getHeight() ,mPaint);
mPaint.setXfermode(xfermode);//PorterDuffXfermode &#x8BBE;&#x7F6E;&#x753B;&#x7B14;&#x7684;&#x56FE;&#x5F62;&#x6DF7;&#x5408;&#x6A21;&#x5F0F;
canvas.drawRoundRect(rectBlackBg, mRadius, mRadius, mPaint);
mPaint.setXfermode(null);
canvas.restoreToCount(layerId);
</code></pre>
<p><img src="../pics/&#x5706;&#x89D2;mask&#x6548;&#x679C;.png" alt=""></p>
<h2 id="&#x901A;&#x8FC7;-bitmapshader-&#x7ED8;&#x5236;&#x5706;&#x89D2;"><a name="&#x901A;&#x8FC7;-bitmapshader-&#x7ED8;&#x5236;&#x5706;&#x89D2;" class="anchor-navigation-ex-anchor" href="#&#x901A;&#x8FC7;-bitmapshader-&#x7ED8;&#x5236;&#x5706;&#x89D2;"><i class="fa fa-link" aria-hidden="true"></i></a>5.2. &#x901A;&#x8FC7; BitmapShader &#x7ED8;&#x5236;&#x5706;&#x89D2;</h2>
<pre><code class="lang-text">&#x539F;&#x7406;&#x5C31;&#x662F; &#x65B0;&#x5EFA;&#x4E00;&#x4E2A; Drawable&#xFF0C;
&#x901A;&#x8FC7; BitmapShader &#x6765;&#x8BBE;&#x7F6E; Paint &#xFF0C;
&#x7ED8;&#x5236;&#x51FA;&#x4E00;&#x4E2A;&#x5706;&#x89D2;&#x77E9;&#x5F62; RectF
canvas.drawRoundRect(rectF, ROUNDVALUE, ROUNDVALUE, mPaint);
&#x6700;&#x540E;&#x7528; ImageView &#x5C06; Drawable &#x663E;&#x793A;&#x51FA;&#x6765;&#x5373;&#x53EF;&#x3002; 

public class RoundedImageDrawable extends Drawable {
    private Paint mPaint;
    private Bitmap mBitmap;
    private RectF rectF;
    private static  final int ROUNDVALUE =60 ;

    public RoundedImageDrawable(Bitmap bitmap)  {
        mBitmap = bitmap;
        BitmapShader bitmapShader = new BitmapShader(bitmap, TileMode.CLAMP, TileMode.CLAMP);
        mPaint = new Paint();
        mPaint.setAntiAlias(true);
        mPaint.setShader(bitmapShader);
    }

    @Override
    public void setBounds(int left, int top, int right, int bottom) {
        super.setBounds(left, top, right, bottom);
        rectF = new RectF(left, top, right, bottom);
    }

    @Override
    public void draw(@NonNull Canvas canvas)  {
        // rx&#xFF1A;x&#x65B9;&#x5411;&#x4E0A;&#x7684;&#x5706;&#x89D2;&#x534A;&#x5F84;&#x3002; ry&#xFF1A;y&#x65B9;&#x5411;&#x4E0A;&#x7684;&#x5706;&#x89D2;&#x534A;&#x5F84;&#x3002;
        canvas.drawRoundRect(rectF, ROUNDVALUE, ROUNDVALUE, mPaint);
    }

    @Override
    public int getIntrinsicWidth() {
        return mBitmap.getWidth();
    }

    @Override
    public int getIntrinsicHeight(){
        return mBitmap.getHeight();
    }

    @Override
    public void setAlpha(int alpha) {
        mPaint.setAlpha(alpha);
    }

    @Override
    public void setColorFilter(ColorFilter cf){
        mPaint.setColorFilter(cf);
    }

    @Override
    public int getOpacity() {
        return PixelFormat.TRANSLUCENT;
    }
}

// &#x4F7F;&#x7528;
imageView.setImageDrawable(new RoundedImageDrawable(bitmap));
</code></pre>
<h2 id="&#x901A;&#x8FC7;-canvasclippath-&#x7ED8;&#x5236;&#x5706;&#x89D2;"><a name="&#x901A;&#x8FC7;-canvasclippath-&#x7ED8;&#x5236;&#x5706;&#x89D2;" class="anchor-navigation-ex-anchor" href="#&#x901A;&#x8FC7;-canvasclippath-&#x7ED8;&#x5236;&#x5706;&#x89D2;"><i class="fa fa-link" aria-hidden="true"></i></a>5.3. &#x901A;&#x8FC7; canvas.clipPath &#x7ED8;&#x5236;&#x5706;&#x89D2;</h2>
<pre><code class="lang-text">&#x539F;&#x7406;&#x975E;&#x5E38;&#x7B80;&#x5355;&#xFF0C;&#x5C31;&#x662F;&#x5B9A;&#x4E49;&#x4E00;&#x4E2A; Path &#xFF0C;
&#x7136;&#x540E;&#x901A;&#x8FC7;  path.moveTo( ) &#x548C;  path.lineTo( ) &#x5B9A;&#x4E49;&#x597D; path &#x7684;&#x8F6E;&#x5ED3;&#xFF0C;
&#x7136;&#x540E;&#x8C03;&#x7528;  canvas.clipPath(path) &#x5C06;&#x8F6E;&#x5ED3;&#x7ED8;&#x5236;&#x51FA;&#x6765;&#x3002;

public class RoundedImageDrawable extends AppCompatImageView {
    private float width, height;
    private  Path path = new Path();

    public RoundedImageDrawable(Context context) {
        this(context, null);
    }

    public RoundedImageDrawable(Context context, AttributeSet attrs) {
        this(context, attrs, 0);
    }

    public RoundedImageDrawable(Context context, AttributeSet attrs, int defStyleAttr) {
        super(context, attrs, defStyleAttr);
        // &#x786C;&#x4EF6;&#x52A0;&#x901F; &#x4F1A;&#x5BFC;&#x81F4;&#x80CC;&#x666F;&#x4E3A;&#x9ED1;&#x8272;&#xFF0C;&#x4E0D;&#x8981;&#x8BBE;&#x7F6E;setLayerType(View.LAYER_TYPE_SOFTWARE, null);
    }

    @Override
    protected void onLayout(boolean changed, int left, int top, int right, int bottom) {
        super.onLayout(changed, left, top, right, bottom);
        width = getWidth();
        height = getHeight();
    }

    private static final int VALUE = 80 ;
    @Override
    protected void onDraw(Canvas canvas) {
        path.reset();
        path.moveTo(VALUE, 0);
        path.lineTo(width - VALUE, 0);
        path.quadTo(width, 0, width, VALUE);
        path.lineTo(width, height - VALUE);
        path.quadTo(width, height, width - VALUE, height);
        path.lineTo(VALUE, height);
        path.quadTo(0, height, 0, height - VALUE);
        path.lineTo(0, VALUE);
        path.quadTo(0, 0, VALUE, 0);
        canvas.clipPath(path);
        super.onDraw(canvas);
    }
}
</code></pre>
<h2 id="&#x901A;&#x8FC7;-viewoutlineprovider-&#x7ED8;&#x5236;-&#x652F;&#x6301;&#x4EFB;&#x4F55;-view-"><a name="&#x901A;&#x8FC7;-viewoutlineprovider-&#x7ED8;&#x5236;-&#x652F;&#x6301;&#x4EFB;&#x4F55;-view-" class="anchor-navigation-ex-anchor" href="#&#x901A;&#x8FC7;-viewoutlineprovider-&#x7ED8;&#x5236;-&#x652F;&#x6301;&#x4EFB;&#x4F55;-view-"><i class="fa fa-link" aria-hidden="true"></i></a>5.4. &#x901A;&#x8FC7; ViewOutlineProvider &#x7ED8;&#x5236; (&#x652F;&#x6301;&#x4EFB;&#x4F55; View )</h2>
<p>&#x76F4;&#x63A5;&#x4F7F;&#x7528; ViewOutlineProvider Added in API level 21 &#xFF0C; Android 5.0 &#x4EE5;&#x4E0A;&#x624D;&#x652F;&#x6301;&#x3002;</p>
<pre><code class="lang-text">private void setClipViewCornerRadius(View view, final int radius) {
    view.setOutlineProvider(new ViewOutlineProvider() {
        @Override
        public void getOutline(View view, Outline outline) {
            outline.setRoundRect(0, 0, view.getWidth(),   view.getHeight(), radius);
        }
    });
    view.setClipToOutline(true);
}
</code></pre>
<h2 id="&#x901A;&#x8FC7;-shapeableimageview-&#x7ED8;&#x5236;-&#x63A8;&#x8350;"><a name="&#x901A;&#x8FC7;-shapeableimageview-&#x7ED8;&#x5236;-&#x63A8;&#x8350;" class="anchor-navigation-ex-anchor" href="#&#x901A;&#x8FC7;-shapeableimageview-&#x7ED8;&#x5236;-&#x63A8;&#x8350;"><i class="fa fa-link" aria-hidden="true"></i></a>5.5. &#x901A;&#x8FC7; ShapeableImageView &#x7ED8;&#x5236; (&#x63A8;&#x8350;)</h2>
<pre><code class="lang-text">// ShapeableImageView &#x662F; material &#x5305;&#x4E0B;&#x7684;&#x4E00;&#x4E2A;&#x63A7;&#x4EF6;&#xFF0C;
&#x5E95;&#x5C42;&#x662F;&#x4F7F;&#x7528;&#x4E86; ViewOutlineProvider &#x6765;&#x5B9E;&#x73B0;&#x7684; &#xFF0C;
ViewOutlineProvider &#x662F;Android&#x5728; 5.0&#x4E4B; &#x540E;&#x63D0;&#x51FA;&#x7684;&#x5BF9; Shape &#x5904;&#x7406;&#x7684;&#x6807;&#x51C6;API&#xFF0C;
&#x5176;&#x6548;&#x7387;&#x4F1A;&#x6BD4;&#x4F20;&#x7EDF;&#x7684;&#x901A;&#x8FC7; Xfermode &#x8FDB;&#x884C;&#x88C1;&#x526A;&#x7684;&#x65B9;&#x5F0F;&#x9AD8;&#x5F88;&#x591A;&#x3002;

implementation &apos;com.google.android.material:material:1.2.0&apos;
&#x6CE8;&#x610F; padding &#x8981;&#x8BBE;&#x7F6E;&#x6210; strokeWidth &#x7684;&#x4E00;&#x534A;&#x3002;

&lt;com.google.android.material.imageview.ShapeableImageView
    android:id=&quot;@+id/image1&quot;
    android:layout_width=&quot;200dp&quot;
    android:layout_height=&quot;200dp&quot;
    android:src=&quot;@mipmap/test&quot;
    app:strokeColor=&quot;#ff0000&quot;
    android:padding=&quot;1dp&quot;
    app:strokeWidth=&quot;2dp&quot;
    app:shapeAppearanceOverlay=&quot;@style/circleImageStyle&quot;/&gt;

&lt;!-- &#x5706;&#x5F62;&#x56FE;&#x7247; --&gt;
&lt;style name=&quot;circleImageStyle&quot;&gt;
    &lt;item name=&quot;cornerFamily&quot;&gt;rounded&lt;/item&gt;
    &lt;item name=&quot;cornerSize&quot;&gt;50%&lt;/item&gt;
&lt;/style&gt;

&lt;!-- &#x5706;&#x89D2;&#x56FE;&#x7247; --&gt;
&lt;style name=&quot;roundedCornerImageStyle&quot;&gt;
    &lt;item name=&quot;cornerFamily&quot;&gt;rounded&lt;/item&gt;
    &lt;item name=&quot;cornerSize&quot;&gt;20%&lt;/item&gt;
&lt;/style&gt;

&lt;!-- &#x5207;&#x89D2;&#x56FE;&#x7247; --&gt;
&lt;style name=&quot;cutImageStyle&quot;&gt;
    &lt;item name=&quot;cornerFamily&quot;&gt;cut&lt;/item&gt;
    &lt;item name=&quot;cornerSize&quot;&gt;15dp&lt;/item&gt;
&lt;/style&gt;

&lt;!-- &#x83F1;&#x5F62;&#x56FE;&#x7247; --&gt;
&lt;style name=&quot;diamondImageStyle&quot;&gt;
    &lt;item name=&quot;cornerFamily&quot;&gt;cut&lt;/item&gt;
    &lt;item name=&quot;cornerSize&quot;&gt;50%&lt;/item&gt;
&lt;/style&gt;

&lt;!-- &#x53F6;&#x5B50;&#x56FE;&#x7247; --&gt;
&lt;style name=&quot;leafImageStyle&quot;&gt;
    &lt;item name=&quot;cornerFamilyTopLeft&quot;&gt;rounded&lt;/item&gt;
    &lt;item name=&quot;cornerFamilyBottomRight&quot;&gt;rounded&lt;/item&gt;
    &lt;item name=&quot;cornerSizeTopLeft&quot;&gt;50%&lt;/item&gt;
    &lt;item name=&quot;cornerSizeBottomRight&quot;&gt;50%&lt;/item&gt;
&lt;/style&gt;
</code></pre>
<h2 id="glide-&#x5B9E;&#x73B0;&#x5706;&#x89D2;"><a name="glide-&#x5B9E;&#x73B0;&#x5706;&#x89D2;" class="anchor-navigation-ex-anchor" href="#glide-&#x5B9E;&#x73B0;&#x5706;&#x89D2;"><i class="fa fa-link" aria-hidden="true"></i></a>5.6. Glide &#x5B9E;&#x73B0;&#x5706;&#x89D2;</h2>
<pre><code class="lang-text">Glide &#x56FE;&#x7247;&#x6846;&#x67B6;&#x53EF;&#x4EE5;&#x76F4;&#x63A5;&#x652F;&#x6301;&#x663E;&#x793A;&#x5706;&#x89D2;&#x56FE;&#x7247;
.transform(RoundedCorners(300))//&#x8BBE;&#x7F6E;&#x5706;&#x89D2;&#x534A;&#x5F84;
</code></pre>
<h2 id="&#x5706;&#x89D2;&#x77E9;&#x5F62;"><a name="&#x5706;&#x89D2;&#x77E9;&#x5F62;" class="anchor-navigation-ex-anchor" href="#&#x5706;&#x89D2;&#x77E9;&#x5F62;"><i class="fa fa-link" aria-hidden="true"></i></a>5.7. &#x5706;&#x89D2;&#x77E9;&#x5F62;</h2>
<pre><code class="lang-text">&#x56DB;&#x4E2A;&#x89D2;&#x7684;&#x5706;&#x89D2;&#x534A;&#x5F84;&#x4E0D;&#x540C;&#x7684;&#x6548;&#x679C;&#x3002;&#x53EF;&#x901A;&#x8FC7; ShapeDrawable &#x6765;&#x5B9E;&#x73B0; &#x3002;
ShapeDrawable drawable = new ShapeDrawable( BgRoundRectShapeTool.getRoundRectShap(mRadius, 0, 0, mRadius) );
drawable.getPaint().setColor( Color.parseColor(&quot;#2fb855&quot;));
drawable.setBounds(0, 0, (int) (mWidth* progressFloat), mHeight);
drawable.draw(canvas);
</code></pre>
<p><img src="../pics/&#x5706;&#x89D2;&#x77E9;&#x5F62;.png" alt=""></p>
<h1 id="&#x5706;&#x89D2;&#x77E9;&#x5F62;&#x80CC;&#x666F;--roundrectshape"><a name="&#x5706;&#x89D2;&#x77E9;&#x5F62;&#x80CC;&#x666F;--roundrectshape" class="anchor-navigation-ex-anchor" href="#&#x5706;&#x89D2;&#x77E9;&#x5F62;&#x80CC;&#x666F;--roundrectshape"><i class="fa fa-link" aria-hidden="true"></i></a>6. &#x5706;&#x89D2;&#x77E9;&#x5F62;&#x80CC;&#x666F;  RoundRectShape</h1>
<p>&#x8FD9;&#x79CD;&#x65B9;&#x5F0F;&#x53EF;&#x4EE5;&#x907F;&#x514D; .9.png &#x5207;&#x7684;&#x4E0D;&#x597D;&#x5BFC;&#x81F4;&#x7684;&#x56FE;&#x7247;&#x6A21;&#x7CCA;&#x95EE;&#x9898;</p>
<pre><code class="lang-text">class BgRoundRectShapeTool  {
    public static RoundRectShape getRoundRectShap(int leftTop, int rightTop, int rightBottom, int leftBottom){
        float []  outerRadii = new float[8];
        if (leftTop &gt; 0) {
            outerRadii[0] = leftTop;
            outerRadii[1] = leftTop;
        }
        if (rightTop &gt; 0) {
            outerRadii[2] = rightTop;
            outerRadii[3] = rightTop;
        }
        if (rightBottom &gt; 0) {
            outerRadii[4] = rightBottom;
            outerRadii[5] = rightBottom;
        }
        if (leftBottom &gt; 0) {
            outerRadii[6] = leftBottom;
            outerRadii[7] = leftBottom;
        }
        return new RoundRectShape(outerRadii, null, null);
    }
}

public class BgDrawable extends StateListDrawable {
    private int buttonPress = 0xFFEAEAEA;
    private int mBackgroundColor = 0xFFf8f8f8 ;
    public BgDrawable(int leftTop, int rightTop, int rightBottom, int leftBottom ) {
        //&#x6309;&#x4E0B;
        ShapeDrawable drawablePress = new ShapeDrawable( BgRoundRectShapeTool.getRoundRectShap(leftTop, rightTop, rightBottom, leftBottom) );
        drawablePress.getPaint().setColor( buttonPress);
        //&#x9ED8;&#x8BA4;
        ShapeDrawable defaultDrawable = new ShapeDrawable( BgRoundRectShapeTool.getRoundRectShap(leftTop, rightTop, rightBottom, leftBottom) );
        defaultDrawable.getPaint().setColor(mBackgroundColor);

        addState(new int[]{android.R.attr.state_pressed}, drawablePress);
        addState(new int[]{-android.R.attr.state_pressed}, defaultDrawable);
    }
}

// &#x4F7F;&#x7528;
textView.setBackground(new BgDrawable(mRadius, mRadius, mRadius, mRadius));
</code></pre>
<p><img src="../pics/&#x5706;&#x89D2;&#x77E9;&#x5F62;drawable.png" alt=""></p>
<h1 id="&#x81EA;&#x5B9A;&#x4E49;&#x63A7;&#x4EF6;&#x793A;&#x4F8B;"><a name="&#x81EA;&#x5B9A;&#x4E49;&#x63A7;&#x4EF6;&#x793A;&#x4F8B;" class="anchor-navigation-ex-anchor" href="#&#x81EA;&#x5B9A;&#x4E49;&#x63A7;&#x4EF6;&#x793A;&#x4F8B;"><i class="fa fa-link" aria-hidden="true"></i></a>7. &#x81EA;&#x5B9A;&#x4E49;&#x63A7;&#x4EF6;&#x793A;&#x4F8B;</h1>
<h2 id="&#x5206;&#x8D1D;&#x6CE2;&#x5F62;&#x56FE;"><a name="&#x5206;&#x8D1D;&#x6CE2;&#x5F62;&#x56FE;" class="anchor-navigation-ex-anchor" href="#&#x5206;&#x8D1D;&#x6CE2;&#x5F62;&#x56FE;"><i class="fa fa-link" aria-hidden="true"></i></a>7.1. &#x5206;&#x8D1D;&#x6CE2;&#x5F62;&#x56FE;</h2>
<pre><code class="lang-text">https://gitee.com/Aivin_CodeShare/android_tool_code/raw/master/AudioWaveView.java
</code></pre>
<p><img src="../pics/201808161609_osChina_&#x5206;&#x8D1D;&#x6CE2;&#x5F62;&#x56FE;.gif" alt="AudioWaveView"></p>
<h2 id="&#x7011;&#x5E03;&#x6D41;"><a name="&#x7011;&#x5E03;&#x6D41;" class="anchor-navigation-ex-anchor" href="#&#x7011;&#x5E03;&#x6D41;"><i class="fa fa-link" aria-hidden="true"></i></a>7.2. &#x7011;&#x5E03;&#x6D41;</h2>
<p>&#x73B0;&#x5728;&#x7684; RecyclerView &#x5DF2;&#x7ECF;&#x76F4;&#x63A5;&#x652F;&#x51FA; &#x7011;&#x5E03;&#x6D41;&#x5E03;&#x5C40;&#x4E86;&#x3002;</p>
<pre><code class="lang-text">// &#x5B9E;&#x73B0;&#x601D;&#x8DEF;
&#x5C06;&#x624B;&#x673A;&#x5C4F;&#x5E55;&#x5206;&#x6210;N&#x5757; &#xFF0C;
&#x6BCF;&#x5F53;&#x9700;&#x8981;&#x6DFB;&#x52A0;&#x4E00;&#x5F20;&#x56FE;&#x7247;&#x65F6;&#xFF0C;&#x4F1A;&#x5C06;&#x8FD9;&#x5F20;&#x56FE;&#x7247;&#x7684;&#x5BBD;&#x5EA6;&#x538B;&#x7F29;&#x6210;&#x548C;&#x5217;&#x4E00;&#x6837;&#x5BBD;&#xFF0C;&#x518D;&#x6309;&#x7167;&#x540C;&#x6837;&#x7684;&#x538B;&#x7F29;&#x6BD4;&#x4F8B;&#x5BF9;&#x56FE;&#x7247;&#x7684;&#x9AD8;&#x5EA6;&#x8FDB;&#x884C;&#x538B;&#x7F29;&#xFF0C;
&#x7136;&#x540E;&#x5728;&#x8FD9;&#x4E09;&#x5217;&#x4E2D;&#x627E;&#x51FA;&#x5F53;&#x524D;&#x9AD8;&#x5EA6;&#x6700;&#x5C0F;&#x7684;&#x4E00;&#x5217;&#xFF0C;&#x5C06;&#x56FE;&#x7247;&#x6DFB;&#x52A0;&#x5230;&#x8FD9;&#x4E00;&#x5217;&#x4E2D;&#x3002;
&#x4E4B;&#x540E;&#x6BCF;&#x5F53;&#x9700;&#x8981;&#x6DFB;&#x52A0;&#x4E00;&#x5F20;&#x65B0;&#x56FE;&#x7247;&#x65F6;&#xFF0C;&#x90FD;&#x53BB;&#x91CD;&#x590D;&#x4E0A;&#x9762;&#x7684;&#x64CD;&#x4F5C;&#xFF0C;&#x5C31;&#x4F1A;&#x5F62;&#x6210;&#x7011;&#x5E03;&#x6D41;&#x683C;&#x5C40;&#x7684;&#x7167;&#x7247;&#x5899;&#x3002;

&#x7136;&#x540E;&#x89E3;&#x51B3;&#x4E0B;&#x5185;&#x5B58;&#x6EA2;&#x51FA;&#x95EE;&#x9898;&#x3002;
</code></pre>
<h2 id="&#x624B;&#x52BF;&#x63A7;&#x4EF6;"><a name="&#x624B;&#x52BF;&#x63A7;&#x4EF6;" class="anchor-navigation-ex-anchor" href="#&#x624B;&#x52BF;&#x63A7;&#x4EF6;"><i class="fa fa-link" aria-hidden="true"></i></a>7.3. &#x624B;&#x52BF;&#x63A7;&#x4EF6;</h2>
<p>GestureDetector &#xFF0C;ScaleGestureDetector &#x3002;
&#x652F;&#x6301;&#x8BC6;&#x522B; &#x5411;&#x5DE6; &#x3001;&#x5411;&#x53F3;&#x3001; &#x5411;&#x4E0A; &#x3001;&#x5411;&#x4E0B; &#x3001;&#x624B;&#x52BF;&#x653E;&#x5927; &#x3001;&#x624B;&#x52BF;&#x7F29;&#x5C0F; &#x3001;&#x505C;&#x6B62;&#x7F29;&#x653E;&#x3001; &#x53CC;&#x51FB;&#x3001; &#x5355;&#x51FB; &#x3001; &#x957F;&#x6309; &#x3002;</p>
<pre><code class="lang-text">https://gitee.com/Aivin_CodeShare/android_tool_code/raw/master/GestureView.java
</code></pre>
<h2 id="&#x4E5D;&#x5BAB;&#x683C;"><a name="&#x4E5D;&#x5BAB;&#x683C;" class="anchor-navigation-ex-anchor" href="#&#x4E5D;&#x5BAB;&#x683C;"><i class="fa fa-link" aria-hidden="true"></i></a>7.4. &#x4E5D;&#x5BAB;&#x683C;</h2>
<pre><code class="lang-text">//&#x601D;&#x8DEF;
&#x5728;xml&#x4E2D;&#xFF0C;&#x4E5D;&#x5BAB;&#x683C;&#x5BBD;&#x5EA6;&#x8BBE;&#x7F6E;&#x4E3A; match_parent ,&#x9AD8;&#x5EA6;&#x8BBE;&#x7F6E;&#x4E3A; wrap_content&#xFF0C;
&#x5728;&#x4EE3;&#x7801;&#x4E2D;&#x8BA1;&#x7B97;&#x5F97;&#x5230;&#x6BCF;&#x4E00;&#x5F20;&#x56FE;&#x7247;&#x7684;&#x5BBD;&#x5EA6;&#x3002;(&#x6839;&#x636E;&#x5BB9;&#x5668;&#x5BBD;&#x5EA6;&#x51CF;&#x53BB;&#x56FE;&#x7247;&#x4E4B;&#x95F4;&#x7684;&#x95F4;&#x9694;&#x548C;&#x5BB9;&#x5668;&#x5DE6;&#x53F3;&#x7684;padding)&#x3002;
&#x7136;&#x540E;&#x6839;&#x636E;&#x81EA;&#x5B9A;&#x4E49;&#x7684;&#x89C4;&#x5219;&#x83B7;&#x53D6;&#x6BCF;&#x4E00;&#x884C;&#x7684;&#x9AD8;&#x5EA6;&#xFF0C;&#x4F8B;&#x5982;&#x9AD8;&#x5EA6;&#x7B49;&#x4E8E;&#x5BBD;&#x5EA6;&#x6216;&#x8005;&#x6309;&#x6BD4;&#x4F8B;&#x83B7;&#x5F97;&#x9AD8;&#x5EA6;&#x7B49;&#x3002;
&#x7136;&#x540E;&#x8C03;&#x7528; addView &#x5C06;&#x56FE;&#x7247;&#x6DFB;&#x52A0;&#x5230; ViewGroup &#x3002;

//demo &#x4EE3;&#x7801;
https://gitee.com/Aivin_CodeShare/android_tool_code/raw/master/NineGridLayout.zip
</code></pre>
<p><img src="../pics/&#x4E5D;&#x5BAB;&#x683C;.png" alt=""></p>
<h2 id="&#x81EA;&#x5B9A;&#x4E49;&#x65E5;&#x5386;&#x63A7;&#x4EF6;"><a name="&#x81EA;&#x5B9A;&#x4E49;&#x65E5;&#x5386;&#x63A7;&#x4EF6;" class="anchor-navigation-ex-anchor" href="#&#x81EA;&#x5B9A;&#x4E49;&#x65E5;&#x5386;&#x63A7;&#x4EF6;"><i class="fa fa-link" aria-hidden="true"></i></a>7.5. &#x81EA;&#x5B9A;&#x4E49;&#x65E5;&#x5386;&#x63A7;&#x4EF6;</h2>
<pre><code class="lang-text">Calendar 
https://gitee.com/Aivin_CodeShare/android_tool_code/raw/master/CalendarDemo.zip

// &#x5F00;&#x6E90;&#x7B2C;&#x4E09;&#x65B9;&#x65E5;&#x5386;
https://github.com/huanghaibin-dev/CalendarView
&#x91CC;&#x9762;&#x6709;&#x5F88;&#x591A;&#x6709;&#x7528;&#x7684;&#x5DE5;&#x5177;&#x7C7B;&#xFF0C;&#x6BD4;&#x5982;&#x83B7;&#x53D6;&#x4E8C;&#x5341;&#x56DB;&#x8282;&#x6C14;&#x3001;&#x519C;&#x5386;&#x8282;&#x65E5;&#x3001;&#x516C;&#x5386;&#x8282;&#x65E5;&#x3001;&#x516C;&#x5386;&#x8F6C;&#x519C;&#x5386;&#x7B49;&#x3002;
</code></pre>
<p><img src="../pics/&#x81EA;&#x5B9A;&#x4E49;&#x65E5;&#x5386;.png" alt=""></p>
<h2 id="&#x52A0;&#x8F7D;&#x7B49;&#x5F85;&#x6846;-&#x3001;&#x83CA;&#x82B1;&#x7B49;&#x5F85;"><a name="&#x52A0;&#x8F7D;&#x7B49;&#x5F85;&#x6846;-&#x3001;&#x83CA;&#x82B1;&#x7B49;&#x5F85;" class="anchor-navigation-ex-anchor" href="#&#x52A0;&#x8F7D;&#x7B49;&#x5F85;&#x6846;-&#x3001;&#x83CA;&#x82B1;&#x7B49;&#x5F85;"><i class="fa fa-link" aria-hidden="true"></i></a>7.6. &#x52A0;&#x8F7D;&#x7B49;&#x5F85;&#x6846; &#x3001;&#x83CA;&#x82B1;&#x7B49;&#x5F85;</h2>
<pre><code class="lang-text">Dialog &#x5168;&#x5C4F;&#x52A0;&#x8F7D;&#x6846;
loadingDialog.getWindow().setLayout(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.MATCH_PARENT);
https://gitee.com/Aivin_CodeShare/android_tool_code/raw/master/LoadingView.zip
</code></pre>
<p><img src="../pics/&#x5168;&#x5C4F;&#x52A0;&#x8F7D;&#x7B49;&#x5F85;.png" alt=""></p>
<h2 id="mpandroidchart-&#x56FE;&#x8868;&#x7ED8;&#x5236;"><a name="mpandroidchart-&#x56FE;&#x8868;&#x7ED8;&#x5236;" class="anchor-navigation-ex-anchor" href="#mpandroidchart-&#x56FE;&#x8868;&#x7ED8;&#x5236;"><i class="fa fa-link" aria-hidden="true"></i></a>7.7. MPAndroidChart &#x56FE;&#x8868;&#x7ED8;&#x5236;</h2>
<pre><code class="lang-text">https://github.com/PhilJay/MPAndroidChart
&#x662F; Android &#x4E2D;&#x4E00;&#x4E2A;&#x8F83;&#x6D41;&#x884C;&#x7684;&#x7B2C;&#x4E09;&#x65B9;&#x5F00;&#x6E90;&#x5E93; &#x3002;
&#x9002;&#x7528;&#x4E8E; Android 2.2 ( API 8 ) &#x53CA;&#x4EE5;&#x4E0A;&#x3002;
&#x672C;&#x6B21;&#x8BB2;&#x89E3;&#x57FA;&#x4E8E; v3.0.3 &#x7248;&#x672C;&#x3002;
MPAndroidChart &#x7684;&#x52A8;&#x753B;&#x673A;&#x5236;&#x53EA;&#x5728;Android API 11  &#x53CA;&#x4EE5;&#x4E0A;&#x6709;&#x6548; &#x3002;
</code></pre>
<footer class="page-footer"><span class="copyright">( no Copyright&#xFF0C;enjoy youself ! ) all right reserved&#xFF0C;powered by Gitbook</span><span class="footer-modification">The file was updated at :
2022-04-04 11:05:23
</span></footer>
                                
                                </section>
                            
    </div>
    <div class="search-results">
        <div class="has-results">
            
            <h1 class="search-results-title"><span class='search-results-count'></span> results matching "<span class='search-query'></span>"</h1>
            <ul class="search-results-list"></ul>
            
        </div>
        <div class="no-results">
            
            <h1 class="search-results-title">No results matching "<span class='search-query'></span>"</h1>
            
        </div>
    </div>
</div>

                        </div>
                    </div>
                
            </div>

            
                
                <a href="事件分发机制.html" class="navigation navigation-prev " aria-label="Previous page: 事件分发机制">
                    <i class="fa fa-angle-left"></i>
                </a>
                
                
                <a href="常用shape.html" class="navigation navigation-next " aria-label="Next page: 常用shape">
                    <i class="fa fa-angle-right"></i>
                </a>
                
            
        
    </div>

    <script>
        var gitbook = gitbook || [];
        gitbook.push(function() {
            gitbook.page.hasChanged({"page":{"title":"控件绘制流程","level":"1.12.7","depth":2,"next":{"title":"常用shape","level":"1.12.8","depth":2,"path":"chinese/android基础/常用shape.md","ref":"chinese/android基础/常用shape.md","articles":[]},"previous":{"title":"事件分发机制","level":"1.12.6","depth":2,"path":"chinese/android基础/事件分发机制.md","ref":"chinese/android基础/事件分发机制.md","articles":[]},"dir":"ltr"},"config":{"plugins":["-search","search-plus","todo","anchor-navigation-ex","copy-code-button","fontsettings","tbfed-pagefooter","local-video","splitter","expandable-chapters","favicon","theme-comscore","local-video"],"styles":{"website":"styles/website.css"},"pluginsConfig":{"tbfed-pagefooter":{"copyright":"( no Copyright，enjoy youself ! )","modify_label":"The file was updated at :","modify_format":"YYYY-MM-DD HH:mm:ss"},"todo":{},"splitter":{},"lunr":{"maxIndexSize":1000000,"ignoreSpecialCharacters":false},"fontsettings":{"family":"sans","size":2,"theme":"white"},"highlight":{},"anchor-navigation-ex":{"associatedWithSummary":true,"float":{"floatIcon":"fa fa-navicon","level1Icon":"","level2Icon":"","level3Icon":"","showLevelIcon":false},"mode":"float","multipleH1":true,"pageTop":{"level1Icon":"","level2Icon":"","level3Icon":"","showLevelIcon":false},"printLog":false,"showGoTop":true,"showLevel":true},"favicon":{"shortcut":"assets/images/favicon.ico","bookmark":"assets/images/favicon.ico"},"theme-comscore":{},"local-video":{},"copy-code-button":{},"sharing":{"facebook":true,"twitter":true,"google":false,"weibo":false,"instapaper":false,"vk":false,"all":["facebook","google","twitter","weibo","instapaper"]},"theme-default":{"styles":{"website":"styles/website.css","pdf":"styles/pdf.css","epub":"styles/epub.css","mobi":"styles/mobi.css","ebook":"styles/ebook.css","print":"styles/print.css"},"showLevel":false},"expandable-chapters":{},"search-plus":{}},"theme":"default","author":"Aivin","pdf":{"pageNumbers":true,"fontSize":12,"fontFamily":"Arial","paperSize":"a4","chapterMark":"pagebreak","pageBreaksBefore":"/","margin":{"right":62,"left":62,"top":56,"bottom":56}},"structure":{"langs":"LANGS.md","readme":"README.md","glossary":"GLOSSARY.md","summary":"SUMMARY.md"},"variables":{},"title":"Aivin开发笔记","language":"zh-hans","gitbook":"*","description":"Aivin开发笔记"},"file":{"path":"chinese/android基础/控件绘制流程.md","mtime":"2022-04-04T03:05:23.525Z","type":"markdown"},"gitbook":{"version":"3.2.3","time":"2022-04-04T03:47:09.782Z"},"basePath":"../..","book":{"language":""}});
        });
    </script>
</div>

        
    <script src="../../gitbook/gitbook.js"></script>
    <script src="../../gitbook/theme.js"></script>
    
        
        <script src="../../gitbook/gitbook-plugin-search-plus/jquery.mark.min.js"></script>
        
    
        
        <script src="../../gitbook/gitbook-plugin-search-plus/search.js"></script>
        
    
        
        <script src="../../gitbook/gitbook-plugin-copy-code-button/toggle.js"></script>
        
    
        
        <script src="../../gitbook/gitbook-plugin-fontsettings/fontsettings.js"></script>
        
    
        
        <script src="../../gitbook/gitbook-plugin-local-video/video.min.js"></script>
        
    
        
        <script src="../../gitbook/gitbook-plugin-splitter/splitter.js"></script>
        
    
        
        <script src="../../gitbook/gitbook-plugin-expandable-chapters/expandable-chapters.js"></script>
        
    
        
        <script src="../../gitbook/gitbook-plugin-lunr/lunr.min.js"></script>
        
    
        
        <script src="../../gitbook/gitbook-plugin-lunr/search-lunr.js"></script>
        
    
        
        <script src="../../gitbook/gitbook-plugin-sharing/buttons.js"></script>
        
    
        
        <script src="../../gitbook/gitbook-plugin-theme-comscore/test.js"></script>
        
    

    </body>
</html>

